How to build a 3D matrix?

조회 수: 1 (최근 30일)
Sarah Sadeq
Sarah Sadeq 2016년 9월 28일
댓글: Sarah Sadeq 2016년 9월 29일
I have a homework assignment that I just need help understanding. We are to make a 4x6x3 matrix, where each column of the image is a single color, in rainbow order (Red, Orange, Yellow, Green, Blue, Purple), but we must use for loops. I'm not quite sure what I'm doing, but I did write a code.
mat=zeros(4,6,3);
row1=[255,0,0];
row2=[0,255,0];
row3=[0,0,255];
for
img(:,col,1)=mycolormap(col,1);
img(:,col,2)=mycolormap(col,2);
img(:,col,3)=mycolormap(col,3);
end
please help me out. I'm new to Matlab and I'm little confused.
  댓글 수: 2
John BG
John BG 2016년 9월 28일
you mean a volume, you want to build a volume?
Sarah Sadeq
Sarah Sadeq 2016년 9월 29일
I'd like to build Build a 4x6x3 matrix, where each column of the$ mage is a single color, in rainbow order

댓글을 달려면 로그인하십시오.

채택된 답변

Walter Roberson
Walter Roberson 2016년 9월 29일
You are close in your approach. You would need
mycolormap = [row1; row2; row3]; %(and extend this for the 6 different colors)
And you would need to fix your for loop.

추가 답변 (0개)

Community Treasure Hunt

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

Start Hunting!

Translated by