How to use fprintf function to display information properly?
3 ビュー (過去 30 日間)
古いコメントを表示
Given: Radius of 10,15,20 ft and height of 6, 12, 18, 24, 30 ft; Volume of a cylinder is pi*r^2*h
Find: Display the various heights and radii, prompt user to enter minimum acceptable volume in ft^3 and display acceptable designs (which will be a logical) that result in a 1.
...
I just want to double check my code here. For some reason my radius and logical are not being displayed side by side, (like a [3x6] matrix), but instead are displaying like a list. It lists in the problem that I MAY need to create an additional matrix that combines the radius column and the logical array but my attemps were futile.
clear; clc; close all;
r=10:5:20;
h=6:6:30;
dvolume=pi.*r.^2.*h';
minvol=input('Enter the minimum acceptable volume in ft^3: ');
req=dvolume>minvol;
%matreq=r;req % This is my attempt to create the matrix putting them in a [3x6] together
fprintf('Acceptable designs include those with a 1.\n')
fprintf('Heights (ft)'); fprintf('%6i',h); fprintf('\n')
fprintf('Radius (ft) \n')
fprintf('%i\n %1.1i\n',r,req)
2 件のコメント
採用された回答
VBBV
2024 年 2 月 23 日
編集済み: VBBV
2024 年 2 月 23 日
clear; clc; close all;
r=10:5:20
h=6:6:30;
dvolume=pi.*r.^2.*h';
minvol= 10; %input('Enter the minimum acceptable volume in ft^3: ');
req=dvolume>minvol
%matreq=r;req % This is my attempt to create the matrix putting them in a [3x6] together
fprintf('Acceptable designs include those with a 1.\n')
fprintf('Heights (ft)'); fprintf('%6i',h); fprintf('\n')
fprintf('Radius (ft) \n')
fprintf('%i %i %i\n',r,req)
9 件のコメント
VBBV
2024 年 2 月 23 日
for input value of 8800 the logical array output is shown as below
clear; clc; close all;
r=10:5:20;
h=6:6:30;
dvolume=pi.*r.^2.*h';
minvol= 8800; %input('Enter the minimum acceptable volume in ft^3: ');
req=dvolume>minvol;
%matreq=r;req % This is my attempt to create the matrix putting them in a [3x6] together
fprintf('Acceptable designs include those with a 1.\n')
fprintf('Heights (ft)'); fprintf('%6i',h); fprintf('\n')
fprintf('Radius (ft) \n')
fprintf('%i %i %i %i %i %i\n',[r;req]) % concatenate vertically
その他の回答 (0 件)
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!