Creating a 3d matrix from different sized matrices
8 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Hello,
I have a total of 29 matrices with with different sized rows (72, 80, 17, 21) and 17 the same number of columns (n = 17)
Each matrix has certain attributes in its name e.g. NPCI14 where NP is the location, CI is the type and 14 is the year
I have :
6 locations (NP, SC, EI, BV, LG and SI)
7 different types (CI, CII > CVII)
3 different years, 14, 15 and 16
I would like to create code to generate a 3d matrix which has the same locations and years 14-16 in the 1st and second dimension and every other location in the third dimension
The second column of each matrix has a number corresponding to the type - e.g. 1, 2,3,4,5,6,7
Hope this makes sense
2 Kommentare
Stephen23
am 5 Mär. 2017
Bearbeitet: Stephen23
am 5 Mär. 2017
"Each matrix has certain attributes in its name e.g. NPCI14 where..."
This how to start writing buggy, slow code.
Read these:
And this quote from the MATLAB documentation: "A frequent use of the eval function is to create sets of variables such as A1, A2, ..., An, but this approach does not use the array processing power of MATLAB and is not recommended"
Then load your data into a single variable (indexing makes this trivial) and you will avoid this whole difficult situation of having 29 separate variables that are difficult to work with. When you load into one variable using indexing then working with your data is trivial using loops or vectorized code.
Antworten (0)
Siehe auch
Kategorien
Mehr zu Matrix Indexing 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!