how to get fprintf to print words with numbers
27 views (last 30 days)
Show older comments
William Colwell
on 29 Oct 2016
Edited: William Colwell
on 29 Oct 2016
How would I be able to use an fprintf statement to print words with corresponding numbers? I am working on a program to calculate the taxes in canada. My issue is creating an fprintf statement that will create a table showing each number in a single line with a province. There are two number variables so I want to make the statement display for example "The tax in Ontario is 20000$ and the difference is 4000$"
thanks in advance for any help
I've tried stuff like this with no luck
fprintf('The tax in %s is %10.2f$ and the difference is %10.2f$\n',provarray{1:end},taxarray)
0 Comments
Accepted Answer
More Answers (1)
James Tursa
on 29 Oct 2016
E.g., assuming provarray is N elements and taxarray is Nx2:
m = max(cellfun(@numel,provarray));
for k=1:numel(provarray)
fprintf(['The tax in %' num2str(m) 's is %10.2f$ and the difference is %10.2f$\n'],provarray{k},taxarray(k,:));
end
1 Comment
See Also
Categories
Find more on File Operations 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!