Filter löschen
Filter löschen

Matrix inserted within a matrix element

2 Ansichten (letzte 30 Tage)
Andy McCann
Andy McCann am 7 Apr. 2012
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

Antworten (1)

Image Analyst
Image Analyst am 7 Apr. 2012
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.

Kategorien

Mehr zu Matrix Indexing finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by