From: Pragya on
Hi,

I'm trying to assign the first element of one array to the corresponding 1st location of another array. Here's the code:
-----------------------------------------------------------------------------
bf=false;
for i=1:20
for j=1:30
if in(i,j)~=0; % in is an input matrix
bf=true;
break;
end
end
if bf
break
end
end
new=[i j];
if p==1
newsaved=[i j];
end
if new(1)<=(newsaved(1)-10)
new(1)=newsaved(1);
end
----------------------------------------------------------------------------------------------------------------
This code works fine for one data matrix 'in' but for another one it gives an error:
.............................................................................................................
??? In an assignment A(I) = B, the number of elements in B and
I must be the same.

Error in ==> featvect0CMU at 31
if new(1)<=(newsaved(1)-10)
.............................................................................................................

What could be the reason? What is the solution?

Thanks
From: ImageAnalyst on
Well what is p? If p == 1, then newsaved(1) and new(1) are both equal
to i, and so your if statement never is true. If p is not 1, then
your newsaved has never been assigned and so it's null and that won't
give expected results in your if statement.

I feel that you left out some code that is key to reproducing your
error.

Can you give some small examples of "in" and what you'd like your
output matrix (is that newsaved?) to look like?
From: Walter Roberson on
Pragya wrote:
> Hi,
>
> I'm trying to assign the first element of one array to the corresponding
> 1st location of another array. Here's the code:
> -----------------------------------------------------------------------------
>
> bf=false;
> for i=1:20
> for j=1:30
> if in(i,j)~=0; % in is an input matrix
> bf=true;
> break;
> end
> end
> if bf
> break
> end
> end
> new=[i j];
> if p==1
> newsaved=[i j];
> end
> if new(1)<=(newsaved(1)-10)
> new(1)=newsaved(1);
> end
> ----------------------------------------------------------------------------------------------------------------
>
> This code works fine for one data matrix 'in' but for another one it
> gives an error:
> .............................................................................................................
>
> ??? In an assignment A(I) = B, the number of elements in B and
> I must be the same.
>
> Error in ==> featvect0CMU at 31
> if new(1)<=(newsaved(1)-10)
> .............................................................................................................
>
>
> What could be the reason? What is the solution?

if p is not 1 then what is newsaved ?