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 Comment

your iterating variable is named "angle" not "row",

Sign in to comment.

Answers (1)

KSSV
KSSV on 22 Jun 2021
Edited: KSSV on 22 Jun 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);

Categories

Find more on Elementary Math in Help Center and File Exchange

Asked:

on 22 Jun 2021

Edited:

on 22 Jun 2021

Community Treasure Hunt

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

Start Hunting!