num2str usage from MATLAB 5.6 to MATLAB 2014b
3 views (last 30 days)
Show older comments
Here is the issue I am having:
I used this code in an earlier version of MATLAB (5.6) and it worked just fine. I have recently installed MATLAB 2014b, and it's showing syntax error on num2str... Below is my code:
Bal = 13123.36;% Balance as of December 13, 2016
n = 70;% number of months
pay = 200 % If You chose to pay this amount in dollars each month on the loan.
out1 = ['Based on a $200 monthly payment and 4.25% interesst'];
out2 = ['Daily rate is .011645% for 30 days, Starting balsnce was $13,123.36 on Dec 13,2016'];
disp(out1);
disp(out2);
for i = 1:n
xint = .0001164*30*Bal;
Prnpay = pay - xint;
Bal = Bal - pay +.0001164*30*Bal;
out =['number ='num2str(i),' Interest ='num2str(xint),' Principle paid ='num2str(Prnpay),' Balance ='num2str(Bal)];
disp(out);
end
Any help would be greatly appreciated! Again, this code works perfectly in MATLAB 5.6 on my old XP VM -- when using the same code in MATLAB 2014b, it complains/underlines each num2str in red - indicating syntax issue of some sort.
--Skywolfe
0 Comments
Answers (2)
Image Analyst
on 5 Apr 2019
Use fprintf():
Bal = 13123.36;% Balance as of December 13, 2016
n = 70;% number of months
pay = 200 % If You chose to pay this amount in dollars each month on the loan.
out1 = ['Based on a $200 monthly payment and 4.25% interesst'];
out2 = ['Daily rate is .011645% for 30 days, Starting balsnce was $13,123.36 on Dec 13,2016'];
disp(out1);
disp(out2);
for k = 1:n
xint = .0001164*30*Bal;
Prnpay = pay - xint;
Bal = Bal - pay +.0001164*30*Bal;
fprintf('number = %d, Interest = %.2f, Principle paid = %.2f, Balance = %.2f\n',...
k, xint,Prnpay,Bal);
end
0 Comments
Fangjun Jiang
on 5 Apr 2019
Not sure what happened, but all you need to do is to insert a whitespace or comma in front of all the num2str() calls.
out =['number =',num2str(i),' Interest =',num2str(xint),' Principle paid =',num2str(Prnpay),' Balance =',num2str(Bal)];
0 Comments
See Also
Categories
Find more on Logical in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!