Hey please i need help with this. if i have these vectors Er=1:3; Ei=0.12.*Er; W=1:0.1:10; how do i generate a vector z based on its relation with W using a for loop in matlab? z={Ei*sin(W) for W<=1 , z={Ei*cos(W) for W>1
3 views (last 30 days)
Show older comments
Er=1:3;
length(Er)=3;
Ei=0.12.*Er;
W=1:0.1:10;
z={Ei*sin(W) for W<=1
z={Ei*cos(W) for W>1
3 Comments
Accepted Answer
madhan ravi
on 4 Nov 2018
Edited: madhan ravi
on 4 Nov 2018
Er=1:3;
length(Er)=3;
Ei=0.12.*Er;
W=0:0.1:10; % I suspect W should start from 0 because of the conditions
z=cell(1);
for i = 1:numel(Ei)
for j = 1:numel(W)
if W(j)<=1
z{i,j}=Ei(i).*sin(W(j));
else
z{i,j}=Ei(i).*cos(W(j)) ;
end
end
end
z ; %cell array
z = cell2mat(z) %double array
12 Comments
madhan ravi
on 4 Nov 2018
If it worked make sure to accept the answer so that people know the question is solved
More Answers (0)
See Also
Categories
Find more on Loops and Conditional Statements in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!