フィルターのクリア

Matrix inserted within a matrix element

2 ビュー (過去 30 日間)
Andy McCann
Andy McCann 2012 年 4 月 7 日
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 Center および File ExchangeMatrix Indexing についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by