How can I create a 3D matrix?
38 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
chia ching lin
le 2 Déc 2020
Commenté : KALYAN ACHARJYA
le 2 Déc 2020
I got three matrix,
num1=linspace(0,1,100);
num2=linspace(0,1,100);
num3=linspace(0,1,100);
how can combine them together to become a 3D matrix ? (formed like below)
(or maybe what I want doesnt called a 3D matrix)?
w is the final matrix i wanted.
>> w(1,1,1)
ans = 0 0 0
>> w(2,1,1)
ans = 0.01 0 0
>> w(100,1,1)
ans = 1 0 0
>> w(2,1,2)
ans = 0.01 0 0.01
>> w(:,1,1)
ans = 0 0 0
0.01 0 0
0.02 0 0
0.03 0 0
...
Or maybe what I want doesnt called a 3D matrix? Any function or keyword I can look up for?
0 commentaires
Réponse acceptée
KALYAN ACHARJYA
le 2 Déc 2020
Modifié(e) : KALYAN ACHARJYA
le 2 Déc 2020
mat_3d=rand(rows_num,columns_mum,depth);
Here depth represents channel number/number of plane slices
Your query ('how can combine them together to become a 3D matrix ?')
num1=linspace(0,1,100);
num2=linspace(0,1,100);
num3=linspace(0,1,100);
result=cat(3,num1,num2,num3);
2nd part:
w(1,1,1)
ans = 0 0 0
For such a case you may look at a multi dimentional cell array for an array stored in a single location. In a multi-dimensional matrix, using w(rows, columns, channel_number) only gives single numeric value. Yes, if you use range numbers or column numbers or ranges of channel numbers, you may get an array as a result.
2 commentaires
KALYAN ACHARJYA
le 2 Déc 2020
"I'm tyring to built a 256x256x256 RGB"
It suppose to have 256 gray planes (Multi dimentional 3 D arrays ), right? Here is the example
result=zeros(256,256,256);
for i=1:256
result(:,:,i)=rand(256,256);
end
Check:
>> whos result
Name Size Bytes Class Attributes
result 256x256x256 134217728 double
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Creating and Concatenating Matrices dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!