How to get separate data set in a for loop
1 view (last 30 days)
Show older comments
Hi, I'm new to this forum and appreciate very much your help!! I need to get a table of Separate set of z2 values for each A value on following code
for A=0:0.01:0.8;
w=0.51;
k=1-exp(1-(G./(2*w)));
at=0.5*(4/pi);
F=37;
v=(13.7*(F.^(1/3)));
n=v/0.04;
for x=-pi/2:0.1:pi/2
C=A*sin(x)-w*cos(x);
if C<0.04
con=n*C;
else con=v;
end
if con<0
CON=0;
else CON=con;
z2=k.*at.*cos(x).*CON.*sin(x);
end
end
end
Answers (2)
Andrew Bliss
on 27 Sep 2017
You need to add an index of some sort to z2. For example:
counter=1;
for A=1:10
z2(counter,1)=A+23;
counter=counter+1;
end
0 Comments
Andrei Bobrov
on 27 Sep 2017
Edited: Andrei Bobrov
on 27 Sep 2017
A = (0:0.01:0.8)';
x = -pi/2:0.1:pi/2;
m = numel(A);
q = numel(x);
w=0.51;
G = 5; %%%%%%%%%%%!!!!!!!!!!!!!!!
k = 1-exp(1-(G./(2*w)));
at = 0.5*(4/pi);
F = 37;
v = (13.7*(F.^(1/3)));
n = v/0.04;
C = bsxfun(@minus,A*sin(x),w*cos(x));
con = n*C;
con(C >= .04) = v;
CON = con;
CON(con < 0) = 0;
z2 = k*at*bsxfun(@times,cos(x).*sin(x),CON);
or
A = (0:0.01:0.8)';
x = -pi/2:0.1:pi/2;
m = numel(A);
q = numel(x);
w=0.51;
G = 5; %%%%%%%%%%%!!!!!!!!!!!!!!!
k = 1-exp(1-(G./(2*w)));
at = 0.5*(4/pi);
F = 37;
v = (13.7*(F.^(1/3)));
n = v/0.04;
z2 = zeros(m,q);
for ii = 1:m % A=0:0.01:0.8;
for jj = 1:q %x=-pi/2:0.1:pi/2
ss = sin(x(jj));
cs = cos(x(jj));
C = A(ii)*ss - w*cs;
if C < 0.04
con = n*C;
else
con = v;
end
if con < 0
CON = 0;
else
CON = con;
end
z2(ii,jj) = k*at*cs*CON*ss;
end
end
0 Comments
See Also
Categories
Find more on Whos 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!