MATLAB Answers

0

while loop mixing number with word

Asked by ali almarzooqi on 12 Aug 2019
Latest activity Edited by the cyclist
on 12 Aug 2019
I want to change the number after the word student in while loop
a = 5;
student1 = a
a=a+5;
student2 = a
a=a+5;
student3 = a
i = 1;
a = 5;
while (i<10)
studenti = a
a=a+5;
i = i+1
end

  0 Comments

Sign in to comment.

Products


Release

R2018b

1 Answer

Answer by the cyclist
on 12 Aug 2019
Edited by the cyclist
on 12 Aug 2019

Use a cell array instead:
i = 1;
a = 5;
while (i<10)
student{i} = a
a=a+5;
i = i+1
end
See this Answers tutorial about why naming variables dynamically is poor programming practice.

  0 Comments

Sign in to comment.