フィルターのクリア

How do I repeat a column vector with a for loop?

1 回表示 (過去 30 日間)
Janell Lopez
Janell Lopez 2016 年 2 月 20 日
コメント済み: Star Strider 2016 年 2 月 20 日
Hi, I'm making a synthetic image for my class, and we have to use a for loop to do so. I have a column vector with the color values in it for one layer, but I need to make it into an mxn matrix so that I can stack them all together at the end for my image. How do I repeat this column vector left to right to make the matrix? I tried something like this:
bottomlayer=linspace(0,1,255);
greenlayer=bottomlayer;
bluelayer=fliplr(greenlayer);
redlayer=flipud(reshape(bottomlayer, [255,1]));
redfinal=zeros(256,256);
for i=1:256
redfinal(:,i)=redlayer;
end
but that gives me an error: "Assignment has more non-singleton rhs dimensions than non-singleton subscripts".
What am I doing wrong? Thanks.

採用された回答

Star Strider
Star Strider 2016 年 2 月 20 日
Your ‘redlayer’ vector is (255x1) and your ‘redfinal’ matrix is (256x256). That causes a dimension mismatch. One of them has to change dimension by 1, and you should be good to go.
  2 件のコメント
Janell Lopez
Janell Lopez 2016 年 2 月 20 日
Oh, wow. Thank you!
Star Strider
Star Strider 2016 年 2 月 20 日
My pleasure!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by