How can I create a 3D matrix?

27 Ansichten (letzte 30 Tage)
chia ching lin
chia ching lin am 2 Dez. 2020
Kommentiert: KALYAN ACHARJYA am 2 Dez. 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?

Akzeptierte Antwort

KALYAN ACHARJYA
KALYAN ACHARJYA am 2 Dez. 2020
Bearbeitet: KALYAN ACHARJYA am 2 Dez. 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 Kommentare
chia ching lin
chia ching lin am 2 Dez. 2020
Bearbeitet: chia ching lin am 2 Dez. 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 am 2 Dez. 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

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Creating and Concatenating Matrices finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by