printing matrix data in the correct order (fprintf)
3 次查看(过去 30 天)
显示 更早的评论
i would like to print this data set in the exact same format, same data on each column and row but matlab prints the rows into columns, im not sure how to print it correctly.
heres what i did:
*the variable name of the matrix below is: data_info;
data to print:
2020 3 21 12 0
2020 3 21 12 10
2020 3 21 12 20
2020 3 21 12 30
2020 3 21 12 40
2020 3 21 12 50
each column is has a corresponding heading: year,month,day,hour,minute
my code:
%transposing the data
trans_alldata = data_info';
%column headings
fprintf('YEAR\tMONTH\tDAY\tHOUR\tMINUTE\n');
%printing only the first 4 lines
fprintf('%d\t%d\t%d\t%d\t%d\n',trans_alldata(1:4,1),trans_alldata(1:4,2),
trans_alldata(1:4,3),trans_alldata(1:4,4),trans_alldata(1:4,5));
COMMAND WINDOW RESULT:
YEAR MONTH DAY HOUR MINUTE
2020 3 21 12 2020
3 21 12 2020 3
21 12 2020 3 21
12 2020 3 21 12
*the data is all messed up
The output i'd like to get:
YEAR MONTH DAY HOUR MINUTE
2020 3 21 12 0
2020 3 21 12 10
2020 3 21 12 20
2020 3 21 12 30
I'd appretiate the help.
0 个评论
回答(1 个)
Star Strider
2022-10-9
data_info = [2020 3 21 12 0
2020 3 21 12 10
2020 3 21 12 20
2020 3 21 12 30
2020 3 21 12 40
2020 3 21 12 50];
trans_alldata = data_info';
fprintf('%d\t%d\t%d\t%d\t%d\n', trans_alldata) % Transpose The Entire Matrix
.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Resizing and Reshaping Matrices 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!