필터 지우기
필터 지우기

For loop ranging from negative to positive integers?

조회 수: 16 (최근 30일)
Austen Thomas
Austen Thomas 2018년 1월 19일
답변: Star Strider 2018년 1월 19일
For the code that is attached i need to run the code for values ranging from -12 to 20

답변 (2개)

Adam
Adam 2018년 1월 19일
Just create an array of e.g.
inputVals = -12:20;
Then use indices in your loop:
for i = 1:numel( inputVals )
AOA(i) = inputVals( i );
CL(i) = a*(AOA(i) - alp0);
fprintf(fid,'%8.4f %8.4f\n',AOA(i),CL(i));
end
Also
doc zeros
gives details on how to create arrays of zeros. You cannot pass negative numbers to this as its inputs are sizes and a negative size makes no sense.

Star Strider
Star Strider 2018년 1월 19일
MATLAB indices must be integers greater than zero (or logical values).
Create your current ‘i’ vector to ‘iv’ (for example), then reference it in your code.
This works:
iv = -12:1:20;
AOA = zeros(size(iv));
CL = zeros(size(iv));
for i = 1:numel(iv)
AOA(i) = iv(i);
CL(i) = a*(AOA(i) - alp0);
fprintf(fid,'%8.4f %8.4f\n',AOA(i),CL(i));
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