I'm using the code
k = 0;
while k<3
k = k+1;
a = 5^k;
disp(a);
end
however, when the result outputs it only gives me the answer of one iteration. I'm wondering what the difference is to the computer when you use this code instead:
clear, clc
k = 0;
while k<3
k = k+1;
a(k) = 5^k;
end
disp(a)
Why does the first code sample output only 125, while the second one outputs 5, 25, and 125?
[5;25; 125], and[5,25,125]for the two codes. Why are you doingwhilerather thanfor?