How do i create a 3D Matrix?
675 ビュー (過去 30 日間)
古いコメントを表示
I have 12 workspace files all 35x43. I want to make them into one 35x43x12 matrix. What is the best way to do so?
Thanks in advance for any help!
3 件のコメント
採用された回答
Stephen23
2014 年 10 月 2 日
編集済み: Stephen23
2014 年 10 月 2 日
If these matrices are existing variables in your workspace, you can concatenate them on the dimension of your choice:
>> A = [1,2;3,4];
>> B = [5,6;7,8];
>> C = [9,10;11,12];
>> Z = cat(3,A,B,C)
Note that in MATLAB it is often easier, faster and neater to keep all data together, and use vectorization to perform operations on the array data In this case, this might mean keeping all of the arrays in one cell array:
>> D = {first_matrix,second_matrix,...};
>> Z = cat(3,D{:})
OR it might even be better to define the data in one array to start with, rather than in twelve separate matrices. Good data planning in MATLAB makes a world of difference to how easy (and readable!) your code will be.
2 件のコメント
Gaia Gbola
2020 年 3 月 9 日
Hello,
I am trying to stack a series of png images, by using a for loop. Could I get help? I keep getting an error by using this code:
clc;clear all;
%A = [imread('frame-3.png') ; imread('frame-4.png');];
for i=1:2456
D = {imread('frame-',(i),'.png')};
Z = cat(3,D{:})
end
imshow(Z)
その他の回答 (1 件)
Stephen23
2014 年 10 月 2 日
編集済み: Stephen23
2014 年 10 月 2 日
A typical way to read multiple files in MATLAB would be:
- Preallocate an array of zeros , using the optional argument to make it size 35x43x12.
- Use a loop to read the data from each file, and allocate the values into the array using some indexing . Note that MATLAB indexing is one-based, and is row-major: X(row,col,3rdDim,4thDim,...)
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Logical についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!