How to shorten space between space in command window

2 ビュー (過去 30 日間)
Geon Jung
Geon Jung 2019 年 9 月 2 日
編集済み: Jan 2019 年 9 月 4 日
clc;clear;
dia_n = input('Write diameter number: ');
dia_min = input('write minimum diameter: ');
dia_max = input('Write maximum diameter: ');
dia = linspace(dia_min, dia_max, dia_n);
den_n = input('Write density number: ');
den_min = input('Write minimum density: ');
den_max = input('Write maximum density: ');
den = linspace(den_min, den_max, den_n);
nLV = input('Write water LV: ');
m = 0;
for a = 1:numel(dia)
fprintf('\nTank Diameter=%.1f meters\nrho/H \n', dia(a));
st_co = dia(a)/nLV;
LV = linspace(st_co, dia(a), nLV);
printLV = sprintf('%0.1f\t\t\t', LV);
fprintf('\t\t\t%s\n\n', printLV)
for b = 1:numel(den)
fprintf('\t%4d', den(b));
for c = 1:numel(LV)
r = dia(a) / 2;
h = LV(c);
v = (pi*h^2*(3*r - h)) / 3;
m(b, c) = den(b) * v;
fprintf('\t%2.0f', m(b, c));
end
fprintf('\n');
end
fprintf('\n');
end
How do I put 0.8 on 2nd column, 1.6 on 3rd, 2.4 on 4th and so on?
I am not sure where exactly I have to change in fprintf.
  3 件のコメント
Geon Jung
Geon Jung 2019 年 9 月 2 日
sorry it was like the first time asking a question here.
And deleting \t did the job. Thanks
Jan
Jan 2019 年 9 月 4 日
@Geon Jung: I've formatted the code for you now.

サインインしてコメントする。

回答 (1 件)

Jan
Jan 2019 年 9 月 4 日
編集済み: Jan 2019 年 9 月 4 日
Avoid the \t for formatting the output if you want to get nice ASCII tables. Prefer to define the width:
fprintf('%s%10d%10d%10d\n', blanks(6), 1:3)
See:
doc fprintf

カテゴリ

Help Center および File ExchangeElectrical Block Libraries についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by