MATLAB Answers

Matrix elements array with specific rule

4 views (last 30 days)
Atique Khan
Atique Khan on 2 Sep 2020
Edited: Stephen Cobeldick on 3 Sep 2020
I have 200 x 200 rgb image which I have splitted into 40 x 40 boxes and each box contains 5 x 5 enteries. The entery of each of 40 x 40 matrix is filled in ssi =yy(1,2).....yy(1,40) in this way I have to write 1600 such lines for each RBG channel. I want to know that is there any way or loop that I can use to build such a list of 1600 enteris each. Kindly help the cose is becoming very large and its very tiring to write 1600 lines for each channel. Thanks a lot for help.
The code is given below and the ss values are only given for first row it has to be done for 40 rows.
[nx,ny] = size(R);
%% to split into kx*ky blocks
kx = 40; ky = 40 ;
I1 = uint8(zeros(nx,ny)) ;
I1(1:nx,1:ny) = R ;
%% Divide into blocks
kx0 = nx/kx ; % rows in block
ky0 = ny/ky ; % columns in block
YY = mat2cell(I1, repmat(kx0,[1 size(I1,1)/kx0]), repmat(ky0,[1 size(I1,2)/ky0]));
ss1=YY{1,1};
ss2=YY{1,2};
ss3=YY{1,3};
ss4=YY{1,4};
ss5=YY{1,5};
ss6=YY{1,6};
ss7=YY{1,7};
ss8=YY{1,8};
ss9=YY{1,9};
ss10=YY{1,10};
ss11=YY{1,11};
ss12=YY{1,12};
ss13=YY{1,13};
ss14=YY{1,14};
ss15=YY{1,15};
ss16=YY{1,16};
ss17=YY{1,17};
ss18=YY{1,18};
ss19=YY{1,19};
ss20=YY{1,20};
ss21=YY{1,21};
ss22=YY{1,22};
ss23=YY{1,23};
ss24=YY{1,24};
ss25=YY{1,25};
ss26=YY{1,26};
ss27=YY{1,27};
ss28=YY{1,28};
ss29=YY{1,29};
ss30=YY{1,30};
ss31=YY{1,31};
ss32=YY{1,32};
ss33=YY{1,33};
ss34=YY{1,34};
ss35=YY{1,35};
ss36=YY{1,36};
ss37=YY{1,37};
ss38=YY{1,38};
ss39=YY{1,39};
ss40=YY{1,40};

  1 Comment

Stephen Cobeldick
Stephen Cobeldick on 3 Sep 2020
"I want to know that is there any way or loop that I can use to build such a list of 1600 enteris"
You already have a "list" of those arrays: that is exactly what the cell array YY is. And you can neatly, efficiently, easily access its contents using indexing.
"Kindly help the cose is becoming very large and its very tiring to write 1600 lines for each channel."
Just use YY and indexing. Much simpler than what you are trying to do.
Numbering variables like that is a sign that you are doing something wrong.

Sign in to comment.

Answers (1)

Steven Lord
Steven Lord on 2 Sep 2020
Creating a large number of variables whose names end in a sequence of numbers is strongly discouraged on Answers. Instead of creating variables ss1, ss2, ... ss1600 why not just type YY{1}, YY{2}, etc. when you need those cells? [You may need to transpose YY in this case, since linear indexing goes down each column first rather than across each row.]

  1 Comment

Atique Khan
Atique Khan on 3 Sep 2020
My YY asigned is same for the three rbg channels. After I store values in ss for red channel gg for green channel and bb for blue channel then will concatinate the image at each pixel back for further processing.

Sign in to comment.

Products


Release

R2016b

Community Treasure Hunt

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

Start Hunting!