fprintf results into 2 columns
4 views (last 30 days)
Show older comments
Hoping someone can help me with the fprintf function... I'm trying to display the results of this into 2 even columns but its taking the results and stacking them....
Looking for the Interest_p and payment variables to display in 2 even lines...
clc; clear; close all;
principal = input('Enter Principal in Dollars: ');
years = input('Enter Number of years: ');
interest=0.0025:0.0025:0.07;
interest_m=interest/12;
n=years*12;
interest_p=interest*100;
payment=principal.*interest_m.*((interest_m+1).^n)./(((1+interest_m).^n)-1);
fprintf('****************************************************\n\n')
fprintf(' MORTGAGE PAYMENT CALCULATIONS\n\n')
fprintf(' Interest Rate Monthly Payment\n')
fprintf(' %3.2f %7.2f\n',interest_p,payment)
fprintf('****************************************************')
2 Comments
Stephen23
on 30 Nov 2022
Edited: Stephen23
on 30 Nov 2022
Without any loop is easy with a minor modification to your code:
principal = 1000;%input('Enter Principal in Dollars: ');
years = 5;%input('Enter Number of years: ');
interest=0.0025:0.0025:0.07;
interest_m=interest/12;
n=years*12;
interest_p=interest*100;
payment=principal.*interest_m.*((interest_m+1).^n)./(((1+interest_m).^n)-1);
%fprintf('****************************************************\n\n')
%fprintf(' MORTGAGE PAYMENT CALCULATIONS\n\n')
%fprintf(' Interest Rate Monthly Payment\n')
fprintf(' %3.2f %7.2f\n',[interest_p;payment]) % changed this line only
%fprintf('****************************************************')
Accepted Answer
VBBV
on 30 Nov 2022
clc; clear; close all;
principal = 1000;%input('Enter Principal in Dollars: ');
years = 5;%input('Enter Number of years: ');
interest=0.0025:0.0025:0.07;
interest_m=interest/12;
n=years*12;
interest_p=interest*100;
payment=principal.*interest_m.*((interest_m+1).^n)./(((1+interest_m).^n)-1)
fprintf('****************************************************\n\n')
fprintf(' MORTGAGE PAYMENT CALCULATIONS\n\n')
fprintf(' Interest Rate Monthly Payment\n')
for k = 1:length(payment)
fprintf(' %3.2f %7.2f\n',interest_p(k), payment(k))
end
fprintf('****************************************************')
More Answers (0)
See Also
Categories
Find more on Particle & Nuclear Physics 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!