![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/687198/image.jpeg)
How to align headings with array elements
4 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Daniel Lardner
el 17 de Jul. de 2021
Comentada: Daniel Lardner
el 18 de Jul. de 2021
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
0 comentarios
Respuesta aceptada
Simon Chan
el 17 de Jul. de 2021
Editada: Simon Chan
el 17 de Jul. de 2021
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))
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/687198/image.jpeg)
Más respuestas (0)
Ver también
Categorías
Más información sobre Crystals en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!