Call one array from a large array made up of several others
조회 수: 1 (최근 30일)
이전 댓글 표시
I've got an array, say Z, made up of 4 smaller 2x2 ones, say A, B, C and D:
Z = a11 a12 b11 b12
a21 a22 b21 b22
c11 c12 d11 d12
c21 c22 d21 d22
Once I've created Z, is there a way to ask matlab for, for example, the first entry in each of A, B, C and D, based only on Z? I can call individual entries from it fine (e.g. the value at the 4th row, 3rd column), but would like to be able to store my data in one array and still treat it as individual arrays for some things.
댓글 수: 0
채택된 답변
sixwwwwww
2013년 12월 5일
you can do it fi you store your arrays A, B, C and D in cell array Z as follows:
Z = {A, B, C, D};
then you can treat A, B, C and D individually by using cell indexing
댓글 수: 3
sixwwwwww
2013년 12월 5일
here is the way you can do it:
% Your matrices A, B, C and D
A = ones(2);
B = A;
C = A;
D = A;
% Cell array of your matrices
Z = {A, B, C, D};
% Now if you want to access A and want to replace its each element with 2 then you can do it as follow
Z{1}(:) = 2;
% Now if you want to access B and want replace its first element with 3 then you can do it as follow
Z{2}(1, 1) = 3;
% Now you can see the changes you made to A and B
disp(Z{1})
disp(Z{2})
In the same way you can easily you use matrices A, B, C and D by using proper cell indexing as described above
참고 항목
카테고리
Help Center 및 File Exchange에서 Matrices and Arrays에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!