## How to name a set of numbers coming out of a loop for fprint

### B_K (view profile)

on 10 Nov 2018
Latest activity Edited by Walter Roberson

### Walter Roberson (view profile)

on 10 Nov 2018
I'm trying to have my loop display each variation up to the certain row I picked.
I can not figure out how to display/fprint my loop with a variable name such as;
I'm trying to do this within only a few fprintf statments without adding more variables.
fileName= 'EXCELDATA';
for i=2:6
time=(i+1);
Acceleration_Data=Data(:,time);
Max_Accel(i)=max(Acceleration_Data);
Min_Accel(i)=min(Acceleration_Data);
fprintf('Maximum Acceleration is %.2f.\n', Max_Accel(i));
fprintf('Minimum Acceleration is %.2f.\n\n', Min_Accel(i));
end
the fprintf output:
Maximum Acceleration is -41.10.
Minimum Acceleration is -90.60.
Maximum Acceleration is 9.30.
Minimum Acceleration is -11.10.
Maximum Acceleration is -0.10.
Minimum Acceleration is -10.70.
what I would like is:
Maximum Acceleration 'in the x' is 10.30.
Minimum Acceleration 'in the x' is -33.30.
Maximum Acceleration 'in the y' is 10.30.
Minimum Acceleration 'in the y' is -33.30.....

R2018b

### Walter Roberson (view profile)

on 10 Nov 2018
Edited by Walter Roberson

### Walter Roberson (view profile)

on 10 Nov 2018

Without a loop:
varnames = {'x', 'y', 'i', 'j', 'k'};
datarows = [varnames(:), num2cell(Max_Accel(:)), varnames(:), num2cell(Min_accel(:))] .';
fprintf('Maximum Acceleration ''in the %s'' is %.2f.\nMinimum Acceleration ''in the %s'' is %.2f.\n\n', datarows{:});
Now, you could get away without an extra variable for the variable names, if you are willing to repeat the content, but it is difficult to get away without the cell array datarows in any situation where you are mixing character and numeric data as parameters.