green
green

Reputation: 713

Is there any way to display numerous output neatly in Matlab?

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

Answers (2)

Jonas
Jonas

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

bla
bla

Reputation: 26069

What about this:

disp(['Friction factor = ' num2str(xxx)])
disp(['Load factor     = ' num2str(yyy)])
disp(['Thermal factor  = ' num2str(zzz)])

Upvotes: 0

Related Questions