How can I create a 3D matrix?
조회 수: 40 (최근 30일)
이전 댓글 표시
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
채택된 답변
KALYAN ACHARJYA
2020년 12월 2일
편집: KALYAN ACHARJYA
2020년 12월 2일
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
KALYAN ACHARJYA
2020년 12월 2일
"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
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!