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:
How to make MATLAB takes NaN as an element

Subject: How to make MATLAB takes NaN as an element

From: Ag

Date: 19 Nov, 2008 12:03:23

Message: 1 of 2

Hello All,


I am trying to reshape n vectors into a matrix. Since the length of the vectors are irregular (i.e. 22, 25, 21, 29, etc..) I've created a vector of 30 and I have asigned a NaN for the remaining cells without values.

Now, that a have all my vectors with the same length of 30 I want to create (squeeze) the matrix but I can't because MATLAB does not considers the NaN cells as elements so my vectors are still irregular. I have tried to replace the NaNs by another value so the full length can be considered vector(vector==NaN)=1000000 but I can't do it neither.

Any ideas??

Thanks in advance

Ag

Subject: How to make MATLAB takes NaN as an element

From: markym

Date: 19 Nov, 2008 12:20:18

Message: 2 of 2

Ag wrote:
> Hello All,
>
>
> I am trying to reshape n vectors into a matrix. Since the length of the vectors are irregular (i.e. 22, 25, 21, 29, etc..) I've created a vector of 30 and I have asigned a NaN for the remaining cells without values.
>
> Now, that a have all my vectors with the same length of 30 I want to create (squeeze) the matrix but I can't because MATLAB does not considers the NaN cells as elements so my vectors are still irregular. I have tried to replace the NaNs by another value so the full length can be considered vector(vector==NaN)=1000000 but I can't do it neither.
>
> Any ideas??

This works perfectly for me:

 >> a = [2 3 NaN];
 >> b = [1 2 3];
 >> A=[a;b]

A =

      2 3 NaN
      1 2 3

 >>

Tags for this Thread

No tags are associated with 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