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)
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
babren
babren on 4 Nov 2018
I am sorry if i was not precise. The output should be 3 sets of the vector z (because Ei has 3 values) for each condition with each vector having the same size as W.

Sign in to comment.

Accepted Answer

madhan ravi
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

Sign in to comment.

More Answers (0)

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!