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:
different length vectors -> one matrix

Subject: different length vectors -> one matrix

From: Hannes Furuholm

Date: 10 Feb, 2011 16:13:03

Message: 1 of 4

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

Subject: different length vectors -> one matrix

From: Sean de

Date: 10 Feb, 2011 18:04:04

Message: 2 of 4

"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

Subject: different length vectors -> one matrix

From: Ramzi

Date: 10 Feb, 2011 23:07:51

Message: 3 of 4

On Feb 10, 7:04 pm, "Sean de "
<sean.dewol...@nospamplease.umit.maine.edu> wrote:
> "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=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
Can we use BSXFUN with arrays of objects (oop) so we can call methods
of a class?

Subject: different length vectors -> one matrix

From: Sean de

Date: 11 Feb, 2011 13:10:05

Message: 4 of 4

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.

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