Creating a 3d matrix from different sized matrices
조회 수: 7 (최근 30일)
이전 댓글 표시
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
Stephen23
2017년 3월 5일
편집: Stephen23
2017년 3월 5일
"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.
답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Matrix Indexing에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!