How to fill a 3D zeros matrix array

19 ビュー (過去 30 日間)
Hugo Hernández Hernández
Hugo Hernández Hernández 2020 年 12 月 9 日
編集済み: James Tursa 2020 年 12 月 9 日
I have created a 3D zeros Matrix
R3_T = zeros(3,3,1442);
And want to fill it using the following computation:
R3_Thot = [cos(Tho_t), sin(Tho_t), z_0; -sin(Tho_t), cos(Tho_t), z_0; z_0, z_0, z_1];
Where:
Tho_t is an array of 1x1442
z_0 is an array of 1x1442 (all zeros)
z_1 is an array of 1x1442(all ones)
Actually I created a Matrix but was filled in the wrong way due to the fact that the elements were not in the correct order, so I got something like this:
While my R3_Thot matrix specifies another order.
Thanks.
Hugo
  1 件のコメント
Hugo Hernández Hernández
Hugo Hernández Hernández 2020 年 12 月 9 日
編集済み: Hugo Hernández Hernández 2020 年 12 月 9 日
I am trying with the following structure:
for i=1:4326
for t=1:1442
R3_T(:,:,t) = [1,2,3;4,5,6;7,8,9];
end
end
But still in a trouble with the arrays of:
R3_Thot = [cos(Tho_t), sin(Tho_t), z_0; -sin(Tho_t), cos(Tho_t), z_0; z_0, z_0, z_1];
Because each element is an array of 1x1442 and does not fit with the for loop above, there should be a way to insert each element with its different 1442 values inside the created matrix. The above for loop is an example which I got this matrices:
Now I want to fill them with those R3_Thot data, but still do not know how.

サインインしてコメントする。

採用された回答

James Tursa
James Tursa 2020 年 12 月 9 日
編集済み: James Tursa 2020 年 12 月 9 日
One way:
c = arrayfun(@(a)[cos(a), sin(a), 0; -sin(a), cos(a), 0; 0, 0, 1],Tho_t,'Uni',false);
result = cat(3,c{:});
Your for-loop would have worked also if you had done this by itself without the outer loop:
for t=1:numel(Tho_t)
R3_T(:,:,t) = [cos(Tho_t(t)), sin(Tho_t(t)), 0; -sin(Tho_t(t)), cos(Tho_t(t)), 0; 0, 0, 1];
end
  1 件のコメント
Hugo Hernández Hernández
Hugo Hernández Hernández 2020 年 12 月 9 日
Thank you very much James!, the first solution worked as expected but for my surprise the second one also worked, I wasn't sure if that could compute the solution that I wanted so I was trying different ways and concatenations in order to get the assignment of my data.
Thanks!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeResizing and Reshaping Matrices についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by