fprintf Command Script Calling

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)

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
1 | 0.78| -0.48745830| 1.5339402482727269e+00| 2 | 0.78| -0.48745830| 1.5339402482727269e+00| 3 | 0.78| -0.48745830| 1.5339402482727269e+00| 4 | 0.78| -0.48745830| 1.5339402482727269e+00| 5 | 0.78| -0.48745830| 1.5339402482727269e+00|

Categories

Find more on MATLAB in Help Center and File Exchange

Products

Release

R2021b

Asked:

on 17 Feb 2022

Answered:

on 17 Feb 2022

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!