Unrecognized function or variable 'row'.
古いコメントを表示
% exampleProgram.m
%
% This program produces an mx1 array of angles named
%of degrees and an mx1 array of the sines of the angles
%named sineAngle.
for angle =0:pi/10:2* pi
degrees (row, 1) = angle*180/pi;
sineAngle( row, 1 ) = sin (angle);
row = row +1;
end
% last line
Unrecognized function or variable 'row'.
1 件のコメント
SALAH ALRABEEI
2021 年 6 月 22 日
your iterating variable is named "angle" not "row",
回答 (1 件)
row = 0 ;
for angle =0:pi/10:2* pi
row = row +1;
degrees (row, 1) = angle*180/pi;
sineAngle( row, 1 ) = sin (angle);
end
But preferred is below code:
angle =0:pi/10:2* pi ;
n = length(angle) ;
degrees = zeros(n,1) ;
sineAngle = zeros(n,1) ;
for i = 1:n
degrees (n) = angle(i)*180/pi;
sineAngle(n) = sin (angle(i));
end
Alos you can vectorize it. No loop needed.
angle =0:pi/10:2* pi ;
degrees = angle*180/pi;
sineAngle = sin (angle);
カテゴリ
ヘルプ センター および File Exchange で Elementary Math についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!