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

回答(1 个)

Image Analyst
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.

类别

Help CenterFile Exchange 中查找有关 Matrix Indexing 的更多信息

标签

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by