[英]if a<x<b in matlab
I need any help for Matlab's thinking method.Ithink I can explaine my problem with a simple example better. 对于Matlab的思维方式,我需要任何帮助。我想可以用一个简单的例子更好地解释我的问题。 Let's say that I have a characteristic function x=y+x0, x0's are may starting values.Then I want to define my function in a grid.Then I define a finer grid and I want to ask him if he knows where an arbitrary (x*,y*) is.To determine it mathematically I should ask where the corresponding starting point (x0*) is.
假设我有一个特征函数x = y + x0,x0是可能的起始值,然后我想在网格中定义函数,然后定义一个更精细的网格,问他是否知道任意( x *,y *)是。为了数学上确定它,我应该问相应的起点(x0 *)在哪里。 If this startig point stay between x(i,1)
如果此起始点停留在x(i,1)之间
clear
%%%%%%%%%%&First grid%%%%%%%%%%%%%%%%%%%%
x0=linspace(0,10,6);
y=linspace(0,5,6);
for i=1:length(x0)
for j=1:length(y)
x(i,j)=y(j)+x0(i);
%%%%%%%%%%%%%%%%%%%Second grid%%%%%%%%%%%%%%%%%%
x0fine=linspace(0,10,10);
yfine=linspace(0,5,10);
for p=1:length(x0fine)
for r=1:length(yfine)
xfine(p,r)=yfine(r)+x0fine(p);
if (x(i,1)<xfine(p,1)')&(x0fine(p,1)'<x(i+1,1))%%%%I probabliy have my first mistake %here
% if y(j)<yfine(r)<y(j+1)
% xint(i,j)=(x(i,j)+x(i,j+1)+x(i+1,j)+x(i+1,j+1))./4;
% else
% xint(i,j)= x(i,j);
%end
end
end
end
end
While a < b < c
is legal MATLAB syntax, I doubt that it does what you think it does. 虽然
a < b < c
是合法的MATLAB语法,但我怀疑它是否按照您的想法去做。 It does not check that a < b
and b < c
. 它不检查
a < b
和b < c
What it does is, it checks whether a < b
, returning a logical value (maybe an array of logicals) and then, interpreting this logical as 0 or 1 , compares it against c: 它的作用是,检查
a < b
是否返回逻辑值(可能是逻辑数组),然后将该逻辑解释为0或1 ,然后将其与c进行比较:
>> 2 < 0 < 2
ans =
1
>> 2 < 0 < 1
ans =
1
>> 0 < 0 < 1
ans =
1
First in matlab you should avoid as much as possible to do loops. 首先,在matlab中,您应尽可能避免执行循环。 For instance you can compute x and xfine, with the following code:
例如,您可以使用以下代码计算x和xfine:
x0=linspace(0,10,6);
y=linspace(0,5,6);
x=bsxfun(@plus,x0',y);
x0fine=linspace(0,10,10);
yfine=linspace(0,5,10);
xfine=bsxfun(@plus,x0fine',yfine);
Then given (X*,y*) your want to fine x0*, in your simple example, you can just do: x0*=x*-y*, I think. 然后给定(X *,y *)您想要罚款x0 *,在您的简单示例中,您可以这样做:x0 * = x * -y *,我想。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.