Displaying different digits in matrix.

Current code :
clc
clear
theta=[50 60 70 80];
thetarad=theta*pi/180;
v=[10 12 14 16 18 20];
h=((v.^2)'*(sin(thetarad)).^2)/(2*9.81);
h1=round(h,1);
tab=[[0,theta];v',h1];
disp(tab)
Disarable result:
Screenshot_2.png

답변 (1개)

Kristoffer Knudsen
Kristoffer Knudsen 2020년 2월 6일
편집: Kristoffer Knudsen 2020년 2월 6일

0 개 추천

You might have some luck with the format command, depending on your needs.
You can put your numbers in a table, allowing you to format the headers (frozen as strings) apart from the data (formatted according to context):
format short % Five digits
t = array2table(h1, 'VariableNames', string(theta), 'RowNames', string(v))
However, to my knowledge, Matlab does not allow user-specified formats for disp. If you have specific needs (such as 'exactly a single number following the decimal point'), you'll have to format the strings yourself.
Creating an array of formatted strings can be done like so:
% Create an array of strings; each string a number formatted appropriately.
s = arrayfun(@(h) sprintf("%0.1f", h), h1)
tab = [string([0, theta]); ...
string(v'), s]

카테고리

도움말 센터File Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

제품

릴리스

R2019b

태그

질문:

2020년 2월 6일

편집:

2020년 2월 6일

Community Treasure Hunt

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

Start Hunting!

Translated by