Homework help, displaying a matrix with a loop

15 次查看(过去 30 天)
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' )

采纳的回答

Geoff Hayes
Geoff Hayes 2019-2-28
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)

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Creating and Concatenating Matrices 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by