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:
Surf plot with NaNs

Subject: Surf plot with NaNs

From: Paul

Date: 14 Jul, 2011 17:50:30

Message: 1 of 3

Hello,
If I have a matrix,

a=
1 NaN 3
2 NaN 8
4 NaN 6

and I plot
surf(1:size(a,2), 1:size(a,1), a)

I am getting an empty plot. I had thought that surf simply ignores NaNs and plots the other values. What am I doing wrong? Thanks!!

Subject: Surf plot with NaNs

From: Sean de

Date: 14 Jul, 2011 19:33:29

Message: 2 of 3

"Paul " <palex71@hotmail.com> wrote in message <ivna96$5em$1@newscl01ah.mathworks.com>...
> Hello,
> If I have a matrix,
>
> a=
> 1 NaN 3
> 2 NaN 8
> 4 NaN 6
>
> and I plot
> surf(1:size(a,2), 1:size(a,1), a)
>
> I am getting an empty plot. I had thought that surf simply ignores NaNs and plots the other values. What am I doing wrong? Thanks!!

It does; there's just not enough data in your above example to create a surface sans nans:

surf(repmat(a,[2 2])) %will have enough adjacent data.

Subject: Surf plot with NaNs

From: Paul

Date: 14 Jul, 2011 20:54:13

Message: 3 of 3

"Sean de " <sean.dewolski@nospamplease.umit.maine.edu> wrote in message <ivnga9$ojh$1@newscl01ah.mathworks.com>...
> "Paul " <palex71@hotmail.com> wrote in message <ivna96$5em$1@newscl01ah.mathworks.com>...
> > Hello,
> > If I have a matrix,
> >
> > a=
> > 1 NaN 3
> > 2 NaN 8
> > 4 NaN 6
> >
> > and I plot
> > surf(1:size(a,2), 1:size(a,1), a)
> >
> > I am getting an empty plot. I had thought that surf simply ignores NaNs and plots the other values. What am I doing wrong? Thanks!!
>
> It does; there's just not enough data in your above example to create a surface sans nans:
>
> surf(repmat(a,[2 2])) %will have enough adjacent data.

Thanks. I'm looking to plot for each value

x = row #
y = column #
z = value of element

I don't quite see how tiling the matrix would do it, though.

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