print output in table format and print the max value

조회 수: 5 (최근 30일)
Senthil
Senthil 2018년 12월 29일
답변: Senthil 2018년 12월 30일
clear all
clc
% Density, kg/m^3
rho=210;
T=2.5;
% Volume , m^3
V=0.018457;
% Diameters, m
for D= [0.05 0.10 0.15 0.20]
% Height, m
H=(V/D^2)*(4/pi);
% Specific rate, kg/m^2h
SR=(H*rho)/T;
fprintf('Dia :%d Height :%d SR :%d\n', [D H SR].')
end
Output Result:
Dia :0.05 Height :9.40007 SR :789.606
Dia :0.1 Height :2.35002 SR :197.402
Dia :0.15 Height :1.04445 SR :87.734
Dia :0.2 Height :0.587505 SR :49.3504
But i need to print the output results like below:
Also need to print, the optimum value is: (Maximum SR value)
Dia: 0.05 Height: 9.40007 SR: 789.606

채택된 답변

Stephen23
Stephen23 2018년 12월 29일
편집: Stephen23 2018년 12월 29일
% Density, kg/m^3
rho = 210;
T = 2.5;
% Volume , m^3
V = 0.018457;
% Diameters, m
D = [0.05 0.10 0.15 0.20];
% Height, m
H = (V./D.^2)*(4/pi);
% Specific rate, kg/m^2h
SR=(H*rho)/T;
% Print:
fprintf('%9s %9s %9s\n','Dia','Height','SR')
fprintf('%9g %9g %9g\n',[D;H;SR])
prints:
Dia Height SR
0.05 9.40007 789.606
0.1 2.35002 197.402
0.15 1.04445 87.734
0.2 0.587505 49.3504
and then:
>> [val,idx] = max(SR);
>> fprintf('Best: Dia: %g Height: %g SR: %g\n',D(idx),H(idx),val)
Best: Dia: 0.05 Height: 9.40007 SR: 789.606

추가 답변 (1개)

Senthil
Senthil 2018년 12월 30일
% Density, kg/m^3
rho = 210;
T = 2.5;
% Volume , m^3
V = 0.018457;
% Diameters, m
D = [0.05 0.10 0.12 0.20];
% Height, m
H = (V./D.^2)*(4/pi);
% Specific rate, kg/m^2h
SR=(H*rho)/T;
% Print:
fprintf('%9s %9s %9s\n','Dia','Height','SR')
fprintf('%9g %9g %9g\n',[D;H;SR])
Output:
Dia Height SR
0.05 9.40007 789.606
0.1 2.35002 197.402
0.12 1.63196 137.084
0.2 0.587505 49.3504
Also i need to print the value as below ( SR in between 100 and 200) is best:
Best: Dia: 0.1 Height: 2.35002 SR: 197.402
Dia: 0.12 Height: 1.63196 SR: 137.084

카테고리

Help CenterFile Exchange에서 Scope Variables and Generate Names에 대해 자세히 알아보기

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by