Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
parsing a matrix

Subject: parsing a matrix

From: Snow White

Date: 2 Jun, 2010 23:06:05

Message: 1 of 3

Hello,

I have written the following code to parse a matrix of size 3x1549849, each row to be converted to 19 matrices of size 271x301.
[Nr,Nc]=size(N);
Ncol=Nc/number_of_images;

xcomp='Nx';ycomp='Ny';zcomp='Nz';
start_Ncol=1;
for(jj=1:number_of_images)
    
    Nx=strcat(xcomp,int2str(jj));
    Ny=strcat(ycomp,int2str(jj));
    Nz=strcat(zcomp,int2str(jj));
    Nx=N(1,start_Ncol:Ncol);
    Ny=N(2,start_Ncol:Ncol);
    Nz=N(3,start_Ncol:Ncol);
    start_Ncol=Ncol+1;
    Ncol=Ncol*(jj+1);
    N_x(jj)=transpose(reshape(Nx,column,row));
    N_y(jj)=transpose(reshape(Ny,column,row));
    N_z(jj)=transpose(reshape(Nz,column,row));
    
end

i get the following error
??? In an assignment A(I) = B, the number of elements in B and
 I must be the same.
 i want to index N_x and so on so that i know which matrix i have to address which has been formed from the original matrix.

Bye

Subject: parsing a matrix

From: Steven Lord

Date: 4 Jun, 2010 02:37:05

Message: 2 of 3


"Snow White" <gulesaman@gmail.com> wrote in message
news:hu6o4t$at1$1@fred.mathworks.com...
> Hello,
>
> I have written the following code to parse a matrix of size 3x1549849,
> each row to be converted to 19 matrices of size 271x301.
> [Nr,Nc]=size(N);
> Ncol=Nc/number_of_images;
>
> xcomp='Nx';ycomp='Ny';zcomp='Nz';
> start_Ncol=1;
> for(jj=1:number_of_images)
> Nx=strcat(xcomp,int2str(jj));
> Ny=strcat(ycomp,int2str(jj));
> Nz=strcat(zcomp,int2str(jj));
> Nx=N(1,start_Ncol:Ncol);
> Ny=N(2,start_Ncol:Ncol);
> Nz=N(3,start_Ncol:Ncol);
> start_Ncol=Ncol+1;
> Ncol=Ncol*(jj+1);
> N_x(jj)=transpose(reshape(Nx,column,row));
> N_y(jj)=transpose(reshape(Ny,column,row));
> N_z(jj)=transpose(reshape(Nz,column,row));
> end
>
> i get the following error
> ??? In an assignment A(I) = B, the number of elements in B and
> I must be the same.

That's correct. On the last three lines of your FOR loop over jj, Nx, Ny,
and Nz will each be row-by-column. However, jj is a scalar. Therefore
you're trying to force a row-by-column matrix into ONE element of N_x, N_y,
or N_z -- and you can't squeeze a matrix like that.

Use a cell array or use an N-D array and fill in each page as appropriate:

M = zeros(2, 3, 4);
x = ceil(5*rand(2, 3));
for k = 1:4
    M(:, :, k) = x.^k;
end

--
Steve Lord
slord@mathworks.com
comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ
To contact Technical Support use the Contact Us link on
http://www.mathworks.com

Subject: parsing a matrix

From: Snow White

Date: 8 Jun, 2010 15:45:21

Message: 3 of 3

Thank you i realized that after i had posted the problem.

"Steven Lord" <slord@mathworks.com> wrote in message <hu9oru$49u$1@fred.mathworks.com>...
>
> "Snow White" <gulesaman@gmail.com> wrote in message
> news:hu6o4t$at1$1@fred.mathworks.com...
> > Hello,
> >
> > I have written the following code to parse a matrix of size 3x1549849,
> > each row to be converted to 19 matrices of size 271x301.
> > [Nr,Nc]=size(N);
> > Ncol=Nc/number_of_images;
> >
> > xcomp='Nx';ycomp='Ny';zcomp='Nz';
> > start_Ncol=1;
> > for(jj=1:number_of_images)
> > Nx=strcat(xcomp,int2str(jj));
> > Ny=strcat(ycomp,int2str(jj));
> > Nz=strcat(zcomp,int2str(jj));
> > Nx=N(1,start_Ncol:Ncol);
> > Ny=N(2,start_Ncol:Ncol);
> > Nz=N(3,start_Ncol:Ncol);
> > start_Ncol=Ncol+1;
> > Ncol=Ncol*(jj+1);
> > N_x(jj)=transpose(reshape(Nx,column,row));
> > N_y(jj)=transpose(reshape(Ny,column,row));
> > N_z(jj)=transpose(reshape(Nz,column,row));
> > end
> >
> > i get the following error
> > ??? In an assignment A(I) = B, the number of elements in B and
> > I must be the same.
>
> That's correct. On the last three lines of your FOR loop over jj, Nx, Ny,
> and Nz will each be row-by-column. However, jj is a scalar. Therefore
> you're trying to force a row-by-column matrix into ONE element of N_x, N_y,
> or N_z -- and you can't squeeze a matrix like that.
>
> Use a cell array or use an N-D array and fill in each page as appropriate:
>
> M = zeros(2, 3, 4);
> x = ceil(5*rand(2, 3));
> for k = 1:4
> M(:, :, k) = x.^k;
> end
>
> --
> Steve Lord
> slord@mathworks.com
> comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ
> To contact Technical Support use the Contact Us link on
> http://www.mathworks.com
>

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us