How to get separate data set in a for loop

조회 수: 1 (최근 30일)
Zanz
Zanz 2017년 9월 26일
편집: Andrei Bobrov 2017년 9월 27일
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

답변 (2개)

Andrew Bliss
Andrew Bliss 2017년 9월 27일
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

Andrei Bobrov
Andrei Bobrov 2017년 9월 27일
편집: Andrei Bobrov 2017년 9월 27일
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

카테고리

Help CenterFile Exchange에서 Whos에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by