필터 지우기
필터 지우기

How to align headings with array elements

조회 수: 4 (최근 30일)
Daniel Lardner
Daniel Lardner 2021년 7월 17일
댓글: Daniel Lardner 2021년 7월 18일
I was hoping to understand how to create additional space in an array so my array elements are aligned with the headings above
% Program that display's distance travelled, Liters of fuel used
% Km/s per liter liters per 100Km
% Define and assign values to variables
% Create functions to calculate Km/L & L/100Km
% Display results
Distance=100; % Km's travelled
Fuel=25; % Litres of fuel used
FConsump=Distance./Fuel; % Calculate Km's per Liter
Economy=Fuel./Distance.*100; % Calculate Litres per 100Km
disp('Distance Liters Used Km/L L/100Km'); % Display headings
disp([Distance, Fuel, FConsump, Economy]); % Display values

채택된 답변

Simon Chan
Simon Chan 2021년 7월 17일
편집: Simon Chan 2021년 7월 17일
Use sprintf and tab, of course, need some manual adjustment.
disp(sprintf('Distance\tLiters Used\tKm/L\tL/100Km'));
disp(sprintf('%d\t\t\t%d\t\t\t%d\t\t%d',Distance, Fuel, FConsump, Economy))
  댓글 수: 1
Daniel Lardner
Daniel Lardner 2021년 7월 18일
Hi Simon,
Thanks for the explanation. I am new to Matlab and was not aware of this function.
Many thanks.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Crystals에 대해 자세히 알아보기

제품


릴리스

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by