Align text after columns when writing in a text file matlab

Hello!
I would like to write data in a text file, but I have problems with the alignment after each column head.
I get something like:
Name Value Dimension Comments
TESTtestNameTest 1 [1 1] Why is not aligned?
SecondXtest 10000000000000 [1 1] And so on?!
When I use these commands (in a for loop) :
fprintf(id_file,'%-50s\t %-80s\t %-10s\t %-10s\n',...
'Name','Value','Dimension','Comments');
for x = 1:length(my_variables)
fprintf(properties,'%-50s\t -80%s\t %-100s\t %-10s\t %-10s\n',...
variable_name{x,1}, variable_value{x,1}, variable_dimension{x,1}, variable_comments{x,1});
end
Is curious that the "Name" and "Values" are always aligning whatever the length of the character written is.
What is wrong?!
Thank you!

5 Comments

Seems that my example was not written as I wanted here.. it was modified after sending my question.
But always the name and the value are under the right column head, but the dimension and comment are shifted and this shifting is done depending on the length of the value.
I hope I made myself understood.
I an writing here again my code because I slipped a mistake:
fprintf(id_file,'%-50s\t %-80s\t %-10s\t %-10s\n',...
'Name','Value','Dimension','Comments');
for x = 1:length(my_variables)
fprintf(properties,'%-50s\t -80%s\t %-10s\t %-10s\n',...
variable_name{x,1}, variable_value{x,1}, variable_dimension{x,1}, variable_comments{x,1});
end
Sorry!!
fprintf(id_file,'%-50s\t %-80s\t %-10s\t %-10s\n',... 'Name','Value','Dimension','Comments'); for x = 1:length(my_variables) fprintf(properties,'%-50s\t -80%s\t %-10s\t %-10s\n',... variable_name{x,1}, variable_value{x,1}, variable_dimension{x,1}, variable_comments{x,1}); end

Sign in to comment.

Answers (0)

Products

Asked:

on 24 Oct 2012

Community Treasure Hunt

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

Start Hunting!