Homework help, displaying a matrix with a loop

5 visualizaciones (últimos 30 días)
Matthew Covington
Matthew Covington el 28 de Feb. de 2019
Comentada: Matthew Covington el 28 de Feb. de 2019
Above is how im supposed to get the following output, which is the lake_powell matrix:
Lake Powell Water Levels (in feet)
2013 2014 2015 2016
3594.38 3563.41 3596.26 3601.41
3589.11 3560.35 3591.94 3598.63
3584.49 3557.42 3589.22 3597.85
3583.02 3557.52 3589.94 3599.75
3584.70 3571.60 3598.27 3604.68
3587.01 3598.06 3609.36 3610.94
3583.07 3607.73 3608.79 3609.47
3575.85 3604.96 3604.93 3605.56
3571.07 3602.20 3602.08 3602.27
3570.70 3602.31 3606.12 3601.27
3569.69 3602.65 3607.46 3599.71
3565.73 3600.14 3604.96 3596.79
How would one go about displaying this matrix a row at a time with a loop?
I currently have this code and got the correct output but I am unsure how to diplay it correctly with a loop:
% read data file
lake_powell = load('lake_powell.txt');
% print title and year column headings
column_headings = [2013, 2014, 2015, 2016];
% print contents of lake_powell
fprintf(' Lake Powell Water Levels (in feet)\n')
fprintf(' %d %d %d %d\n', column_headings)
fprintf(' %6.2f %6.2f %6.2f %6.2f\n', lake_powell' )

Respuesta aceptada

Geoff Hayes
Geoff Hayes el 28 de Feb. de 2019
Matthew - since this is homework... to get the number of rows of lake_powell use size and then a for loop to iterate over each row. You should be able to extract the kth row and use fprintf in the same way you have for
fprintf(' %d %d %d %d\n', column_headings)

Más respuestas (0)

Categorías

Más información sobre Creating and Concatenating Matrices 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!

Translated by