for loop

6 次查看(过去 30 天)
Kugen Raj
Kugen Raj 2012-3-22
if size(qq)==[1,8]
ff=[(hh(1,1)+qq(1,2))];
ff1=[(hh(1,1)+qq(1,4))];
ff2=[(hh(1,1)+qq(1,6))];
ff3=[(hh(1,1)+qq(1,8))];
aa=kk(ff);
aa1=kk(ff1);
aa2=kk(ff2);
aa3=kk(ff3);
elseif size(qq)==[1,6] / size(qq)==[1,7]
ff=[(hh(1,1)+qq(1,2))];
ff1=[(hh(1,1)+qq(1,4))];
ff2=[(hh(1,1)+qq(1,6))];
aa=kk(ff);
aa1=kk(ff1);
aa2=kk(ff2);
elseif size(qq)==[1,4] / size(qq)==[1,5]
ff=[(hh(1,1)+qq(1,2))];
ff1=[(hh(1,1)+qq(1,4))];
aa=kk(ff);
aa1=kk(ff1);
elseif size(qq)==[1,2] / size(qq)==[1,3]
ff=[(hh(1,1)+qq(1,2))];
aa=kk(ff);
end
based on my coding, i want to calculate (aa-aa3) if the size(qq)=[1,8], (aa-aa2) if size(qq)=[1,6], (aa-aa1) of size(qq)=[1,4] and (aa only) if the size(qq)=[1,2]. Is this code correct because im not sure if it works properly.

回答(1 个)

Nathan Greco
Nathan Greco 2012-3-22
The only thing that doesn't look right to me is where you have
elseif size(qq)==[1,#] / size(qq)==[1,#+1]
Where # is 6,4,2 Why do you have the second half there? I would get rid of that and just put
elseif size(qq)==[1,#]
And so on. Note: If you wanted to say if size(qq) is less than or equal to [1,3], you would need an | as such:
elseif size(qq)==[1,#] | size(qq)==[1,#+1]
-Nathan
  2 个评论
Kugen Raj
Kugen Raj 2012-3-22
how do I put it, if i want to calculate (aa-aa2) in the condition where size(qq)=[1,8] or size(qq)=[1,7]. i will have to put like size(qq)=[1,8] | size(qq)=[1,7] ?
Nathan Greco
Nathan Greco 2012-3-22
Yes, just replace your /'s with |'s.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Loops and Conditional Statements 的更多信息

标签

尚未输入任何标签。

产品

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by