How can I create a 3D matrix?

38 vues (au cours des 30 derniers jours)
chia ching lin
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?

Réponse acceptée

KALYAN ACHARJYA
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
chia ching lin
chia ching lin le 2 Déc 2020
Modifié(e) : chia ching lin le 2 Déc 2020
Thanks for answering. I've consider using cat(3, ) before, but the result wasn't quite what i'm thinking for. I'm expecting that I can call a 1x3 double array from th result.
I'm tyring to built a 256x256x256 RGB color matrix that I can call the color from it. For example red=result(256,0,0), green=result(0,256,0), blue=result(0,0,256).
orange is from result(0,1,2)~result(0,128,256)
KALYAN ACHARJYA
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

Connectez-vous pour commenter.

Plus de réponses (0)

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!

Translated by