printing matrix data in the correct order (fprintf)

3 Ansichten (letzte 30 Tage)
Aya
Aya am 9 Okt. 2022
Beantwortet: Star Strider am 9 Okt. 2022
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.

Antworten (1)

Star Strider
Star Strider am 9 Okt. 2022
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
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
.

Kategorien

Mehr zu Resizing and Reshaping Matrices finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by