How to do while loop on arrays?
Show older comments
Hi there, I'm new to matlab, I'm having problem doing while loop on arrays. Apparently the logic for the while loop is wrong, it should go row by row until E equals to zero...can someone help please? It's kind of urgent. Thanks!
A=5000;
B=4000;
C=3000;
D=2000;
E=1000;
i=1;% row 1
i=[A B C D E]
%---------do this first----------------
%while i(1,5)>0 %the logic here is that value E should be more than zero to proceed
i(1,1)=i(1,5); %beginning balance row 2
i(1,2)=i(1,1)*1.5/12 %interest row 2
i(1,3)=i(1,2)-i(1,3); %principal row 2
i(1,4)=i(1,1)-i(1,4); %ending balance row 2
i=i+1;
i=[i;i(1,1),i(1,2),i(1,3),i(1,4),i(1,5)];
%------formula-------------------------
%‹end
2 Comments
David Fletcher
on 4 Apr 2021
i=1;% row 1
i=[A B C D E]
I'm not really sure I have much of a clue what you are doing, but do you really want to declare i=1 and then immediately overwrite it with a vector.
Phoebe
on 5 Apr 2021
Accepted Answer
More Answers (0)
Categories
Find more on Logical in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!