COMPGROUPS.NET | Search | Post Question | Groups | Stream | About | Register

### different length vectors -> one matrix

• Follow

```Hi! Newbie here..
I have a matrix (100x36) and a vector (1x36). The values of the vector are somewhat similar to the ones in the matrix, and what I want to do is to find (and list) which values in the matrix that exceeds the vector values by more than "10". And this for each of the 36 different columns.

However, since there are different amount of exceeding numbers for each of the 36 columns, it seems like a regular for-loop wont work.

for i=1:36
s(i)=find(matrix(:,F(i))>(vector(i)+10));
end

this since "s" would not have sufficient number of elements. I have i.e. 36 new vectors of different length and want to put them all in a new matrix. Is this even possible?

I hope my problem is understandable, any suggestions on how I should approach it? I might add that my code works well as long as I just do it one vector at a time (replacing the index with a specific column number).

Best regards
// Hannes
```
 0

```"Hannes Furuholm" wrote in message <ij12qf\$69\$1@fred.mathworks.com>...
> Hi! Newbie here..
> I have a matrix (100x36) and a vector (1x36). The values of the vector are somewhat similar to the ones in the matrix, and what I want to do is to find (and list) which values in the matrix that exceeds the vector values by more than "10". And this for each of the 36 different columns.
>
> However, since there are different amount of exceeding numbers for each of the 36 columns, it seems like a regular for-loop wont work.
>
> for i=1:36
> s(i)=find(matrix(:,F(i))>(vector(i)+10));
> end
>
> this since "s" would not have sufficient number of elements. I have i.e. 36 new vectors of different length and want to put them all in a new matrix. Is this even possible?
>
> I hope my problem is understandable, any suggestions on how I should approach it? I might add that my code works well as long as I just do it one vector at a time (replacing the index with a specific column number).
>
> Best regards
> // Hannes

No reason for a for-loop.  That why they made BSXFUN.

%Data
A = 1:36;
B = floor(rand(100,36)*50);

%Engine
sum(bsxfun(@(x,y)(y-x)>10,A,B))

%SCd
```
 0

```On Feb 10, 7:04=A0pm, "Sean de "
> "Hannes Furuholm" wrote in message <ij12qf\$6...@fred.mathworks.com>...
> > Hi! Newbie here..
> > I have a matrix (100x36) and a vector (1x36). The values of the vector =
are somewhat similar to the ones in the matrix, and what I want to do is to=
find (and list) which values in the matrix that exceeds the vector values =
by more than "10". And this for each of the 36 different columns.
>
> > However, since there are different amount of exceeding numbers for each=
of the 36 columns, it seems like a regular for-loop wont work.
>
> > for i=3D1:36
> > s(i)=3Dfind(matrix(:,F(i))>(vector(i)+10));
> > end
>
> > this since "s" would not have sufficient number of elements. I have i.e=
.. 36 new vectors of different length and want to put them all in a new matr=
ix. Is this even possible?
>
> > I hope my problem is understandable, any suggestions on how I should ap=
proach it? I might add that my code works well as long as I just do it one =
vector at a time (replacing the index with a specific column number).
>
> > Best regards
> > // Hannes
>
> No reason for a for-loop. =A0That why they made BSXFUN.
>
> %Data
> A =3D 1:36;
> B =3D floor(rand(100,36)*50);
>
> %Engine
> sum(bsxfun(@(x,y)(y-x)>10,A,B))
>
> %SCd
Can we use BSXFUN with arrays of objects (oop) so we can call methods
of a class?
```
 0

```Ramzi <ramzib2@gmail.com> wrote in message <79c9883b-531c-4164-
> Can we use BSXFUN with arrays of objects (oop) so we can call methods
> of a class?

Not a user of OOP (yet at least), but I'd assume you could use BSXFUN if you define it as a private function for that class.
```
 0

3 Replies
415 Views

Similiar Articles:

7/22/2012 5:32:38 AM