How can I use for loop twice

조회 수: 2 (최근 30일)
omkar bichkar
omkar bichkar 2015년 6월 13일
편집: Azzi Abdelmalek 2015년 6월 13일
error: for | Error: Expression or statement is incomplete or incorrect.
syms x
Fun = (sqrt(7.447.*(200-x).*(2.0720.*x-200.*sqrt(9.01)+sqrt(9.01.*200^2- 7.9810*200.*x))))/8;
h=1;
zi = 1:360;
x=0:h:200;
Fun1 = matlabFunction(Fun);
for i=1:(length(x)-1)
for
j=1:360
end
y1 = Fun1(x(i));
z1 = Fun1(x(i));
x2 = x(i)+h;
y2 = Fun1(x(i+1));
z2 = Fun1(x(i+1));
x3 = x(i)+h;
y3 = y2*cos((pi/180)*zi(j));
z3 = z2*sin((pi/180)*zi(j));
T1 = [0, y3-y2, z3-z2];
T2 = [x(i)-x(i+1), y1-y2, z1-z2];
Vec = cross(T1,T2);
deltal = sqrt((y2-y1)^2+h^2);
deltazi = sqrt(z3^2+(y2-y3)^2);
dA11 = deltal.*deltazi;
end
please help me

채택된 답변

Azzi Abdelmalek
Azzi Abdelmalek 2015년 6월 13일
편집: Azzi Abdelmalek 2015년 6월 13일
Look at this part of your code
for
j=1:360
end
It's not correct, and even it's corrected
for j=1:360
end
This doesn't mean anything, maybe what you want is this:
syms x
Fun = (sqrt(7.447.*(200-x).*(2.0720.*x-200.*sqrt(9.01)+sqrt(9.01.*200^2- 7.9810*200.*x))))/8;
h=1;
zi = 1:360;
x=0:h:200;
Fun1 = matlabFunction(Fun);
for i=1:(length(x)-1)
y1 = Fun1(x(i));
z1 = Fun1(x(i));
x2 = x(i)+h;
y2 = Fun1(x(i+1));
z2 = Fun1(x(i+1));
x3 = x(i)+h;
for j=1:360
y3 = y2*cos((pi/180)*zi(j));
z3 = z2*sin((pi/180)*zi(j));
T1 = [0, y3-y2, z3-z2];
T2 = [x(i)-x(i+1), y1-y2, z1-z2];
Vec = cross(T1,T2);
deltal = sqrt((y2-y1)^2+h^2);
deltazi = sqrt(z3^2+(y2-y3)^2);
dA11 = deltal.*deltazi;
end
end

추가 답변 (1개)

Mischa Kim
Mischa Kim 2015년 6월 13일
Hi Omkar, looks like the second end is misplaced. Als, I recommend using ii instead of i (and same for j) because it is also used as the imaginary unit.
Fun1 = matlabFunction(Fun);
for i = 1:(length(x)-1) %%replace i by ii
for j = 1:360 %%replace j by jj
y1 = Fun1(x(i));
z1 = Fun1(x(i));
x2 = x(i)+h;
y2 = Fun1(x(i+1));
z2 = Fun1(x(i+1));
x3 = x(i)+h;
y3 = y2*cos((pi/180)*zi(j));
z3 = z2*sin((pi/180)*zi(j));
T1 = [0, y3-y2, z3-z2];
T2 = [x(i)-x(i+1), y1-y2, z1-z2];
Vec = cross(T1,T2);
deltal = sqrt((y2-y1)^2+h^2);
deltazi = sqrt(z3^2+(y2-y3)^2);
dA11 = deltal.*deltazi;
end
end

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by