Matrix inserted within a matrix element
조회 수: 2 (최근 30일)
이전 댓글 표시
Hi, I'm looking for help replacing an element of a matrix with a new matrix. I have a large matrix where i wish to replace every element with a 1x3 row vector, is this possible? If not you may be able to suggest a different approach. Essentially i wish for every element in a matrix to contain the values for a spherical polar vector. So a value for r, theta and phi. Is there a better way to do this, short of making the original vector 3 times as long, as this causes problems in addressing the entries. Thanks Andy
댓글 수: 0
답변 (1개)
Image Analyst
2012년 4월 7일
So just add a third dimension
m=rand(5,5) % Create sample data.
% Now we want three numbers at each location insted of 1.
% So add a dimension with 2 more planes
blankPlane = zeros(size(m))
m = cat(3, m, blankPlane, blankPlane)
% Assign a 1x3 row vector to the 1,1 location
rowVector = [1 2 3] % Create row vector.
m(1,1,:) = rowVector;
% Let's do it again at the 3,3 location.
rowVector = [10 20 30] % Create row vector.
m(3,3,:) = rowVector
You might have t in plane 1 m(:,:,1), theta might be in plane 2 m(:,:,2), and you might have phi in plane 3 m(:,:,3), or however you want to do it.
댓글 수: 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!