How to use ' fprintf ' to display vector
133 views (last 30 days)
Show older comments
fprintf(.......)
% The result :
==> The vector P is: [6, 7, 3.1, 0 , 4.6, 8]
0 Comments
Answers (3)
Image Analyst
on 12 Oct 2018
Try this:
P = [6, 7, 3.1, 0 , 4.6, 8];
fprintf('The vector P is: [');
fprintf('%g ', P);
fprintf(']\n');
3 Comments
Image Analyst
on 28 Dec 2020
If commas are wanted:
P = [6, 7, 3.1, 0 , 4.6, 8];
fprintf('The vector P is: [');
fprintf('%g, ', P(1:end-1));
fprintf('%g]\n', P(end));
Shows
The vector P is: [6, 7, 3.1, 0, 4.6, 8]
Walter Roberson
on 12 Oct 2018
If it must be done with one fprintf(), then dynamically generate the format.
fmt = ['The vector P is: [', repmat('%g, ', 1, numel(P)-1), '%g]\n'];
fprintf(fmt, P)
0 Comments
Amit
on 23 Apr 2023
fprientf (‘The Integral value using trapezoidal rule :%.4f\n’,integral_value)
1 Comment
See Also
Categories
Find more on Other Formats 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!