introducing a specified indent in the output text file

5 views (last 30 days)
I am trying to introduce in a specified indent in fprintf ...to get a certain output of the file. \t was not a big help, it was giving a tab from the string before it..and in every line the strings are of different length.
output:
lat_to_long_tread_stiffn_ratio = 0.995941 $ -
sidewall_to_tread_stiffn_ratio = 0.1 $ -
damping_tread_rubber = 3.33e-05 $ s
desired output:
lat_to_long_tread_stiffn_ratio = 0.995941 $ -
sidewall_to_tread_stiffn_ratio = 0.1 $ -
damping_tread_rubber = 3.33e-05 $ s
max_friction_velocity = 14.1877 $ mm/s
sliding_velocity = 149.718 $ mm/s
blocking_velocity = 19623.8 $ mm/s
low_ground_pressure = 0 $ bar

Answers (1)

Jan
Jan on 14 Apr 2015
Edited: Jan on 14 Apr 2015
fprintf('%31s= %23.6f $ %s\n', 'lat_to_long_tread_stiffn_ratio', 0.995941, '-');
  2 Comments
shivam arora
shivam arora on 14 Apr 2015
the input is consists of various cells, generated from textscan, to read in the original file. I have to modify few of the values. So:
breakdown = textscan(fid,'%s%s%s','delimiter',{'=','$'});
and to print i am doing :
for idx = 1 : length(breakdown{1,1})
fprintf(fid1,' %s =\t\t\t\t\t\t%s\t\t$ %s\n',breakdown{1,1}{idx},breakdown{1,2}{idx},breakdown{1,3}{idx});
end
thanks for your inputs
shivam arora
shivam arora on 14 Apr 2015
thanks a lot for your answer. it sort of works but I want the 1st char values to start from the same place as well. So it should be:
lat_to_long_tread_stiffn_ratio = 0.995941 $ -
max_friction_velocity = 14.1877 $ mm/s
but what i am getting is:
lat_to_long_tread_stiffn_ratio = 0.995941 $ -
max_friction_velocity = 14.1877 $ mm/s

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!