fprintf Command Script Calling
Show older comments
for i = 1:5
fprintf ('1 |%8.2f|%16.8f| % 20.16e| /n', x);
end
Here is the script I have so far. I am calling a script and x is a variable in another script I am calling into this one. Variable x is an array of variables generated randomly. With what I have reproduced so far I need five rows, numbered with a different output. My current output lookes like this:

I want five rows total not including the header row that mimic the first row where it begins: 1 | -38.35 | .... All of the rows will have random numbers except the first column which I am trying to get 1:5 (1 through 5). So the second row should begin: 2 | 75.61 | ... and so on to 5 | ---- |... Thank you!
Answers (2)
Walter Roberson
on 17 Feb 2022
for i = 1:5
fprintf ('%d |%8.2f|%16.8f| % 20.16e| /n', i, x);
end
x = randn(1,3);
for i = 1:5
fprintf('%d |%8.2f|%16.8f| % 20.16e| \n', i, x);
end
Categories
Find more on MATLAB 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!