Reputation: 713
Suppose I have numerous number of outputs and I want them to show as follow
Friction factor = xxx
Load factor = xxx
Thermal factor = xxxx
Is there any way to make the equal sign '=' align to each other? I've tried using the 'fprintf' function with '\t'. However, it's tough for me to achieve such arrangement.
Sincerely thank you for all the helps.
Upvotes: 0
Views: 987
Reputation: 74940
You could do the following:
names = {'Friction Factor','Load Factor','Thermal Factor'};
values = [xx,yy,zz];
nameLength = cellfun(@numel,names);
format = sprintf('%%-%is = %%f\\n',max(nameLength));
for n = 1:length(names)
fprintf(format,names{n},values(n));
end
Upvotes: 4
Reputation: 26069
What about this:
disp(['Friction factor = ' num2str(xxx)])
disp(['Load factor = ' num2str(yyy)])
disp(['Thermal factor = ' num2str(zzz)])
Upvotes: 0