Info

This question is closed. Reopen it to edit or answer.

while loop mixing number with word

1 view (last 30 days)
ali almarzooqi
ali almarzooqi on 12 Aug 2019
Closed: MATLAB Answer Bot on 20 Aug 2021
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

Answers (1)

the cyclist
the cyclist on 12 Aug 2019
Edited: 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.

Products


Release

R2018b

Community Treasure Hunt

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

Start Hunting!