Unrecognized function or variable 'row'.
7 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
% 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 Commento
Risposte (1)
KSSV
il 22 Giu 2021
Modificato: KSSV
il 22 Giu 2021
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);
0 Commenti
Vedere anche
Categorie
Scopri di più su Creating and Concatenating Matrices in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!