Matrix row and column headers
13 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
I have created a 15 x 15 arrray called M.
This array should have 15 city names going across the top and then the same 15 city names going across the side. Row & Column headers. I have made the array and row header, I cannot make the column header for some peculiar reason.
M = [0,1...] //my matrix
Rows = {'Portland'; 'St. Louis'; ... } //works fine i get a Rows list that is 15 x 1
Columns = {'Portland', 'St. Louis', ... } // My attempt to make a 1 x 15 column list. Fails everytime.
Can someone help me to make a columns header then add it and my row headers to my Array? I have looked up many questions but I cannot get past making the columns header.
0 Kommentare
Antworten (1)
Akshat
am 5 Nov. 2024 um 11:24
To give row and column headers to your matrix in MATLAB, I would strongly recommend using the data structure called "table" in MATLAB.
There is a function called "array2table" in MATLAB, using which you can make a pre existing matrix into a table, with row headers and column headers.
The documentation regarding "array2table" can be found on this link:
A boilerplate code to suit your use case can be seen as follows:
M = randi(100, 15, 15); % Replace with your actual data
Rows = {'Portland'; 'St. Louis'; 'New York'; 'Los Angeles'; 'Chicago';
'Houston'; 'Phoenix'; 'Philadelphia'; 'San Antonio'; 'San Diego';
'Dallas'; 'San Jose'; 'Austin'; 'Jacksonville'; 'Fort Worth'};
Columns = {'Portland', 'St. Louis', 'New York', 'Los Angeles', 'Chicago',
'Houston', 'Phoenix', 'Philadelphia', 'San Antonio', 'San Diego',
'Dallas', 'San Jose', 'Austin', 'Jacksonville', 'Fort Worth'};
T = array2table(M, 'VariableNames', Columns, 'RowNames', Rows);
disp(T);
Let me know in the comments if you have any further questions!
0 Kommentare
Siehe auch
Kategorien
Mehr zu Logical 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!