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:
Repmat help

Subject: Repmat help

From: Claire

Date: 18 Sep, 2010 02:13:05

Message: 1 of 9

I am trying to use the scatter3 function to create a 3D plot of some oceanographic data that I have. In order to use the scatter3 function, I need to get my vectors to be the same length. I am trying to use repmat to do this.

I have three inputs of varying lengths
1) Latitude = 101
2) Longitude = 720
3) Depth = 40

I am trying to use repmat to change the size of these vectors to 101x720x40 for my plot, but I can't seem to get it to work. When I use the repmat function for longitude:

y2=repmat(lon,[1,720,40]);
I get an output size 720x720x40. I can only use integers with repmat, but I don't see how I can get my output to be 101x720x40 without using a fraction.

I'm sure I am just doing something stupid, but I would really appreciate some help.

Thanks!
Claire

Subject: Repmat help

From: Roger Stafford

Date: 18 Sep, 2010 02:23:05

Message: 2 of 9

"Claire " <claire.davis@students.mq.edu.au> wrote in message <i7177h$5t6$1@fred.mathworks.com>...
> I am trying to use the scatter3 function to create a 3D plot of some oceanographic data that I have. In order to use the scatter3 function, I need to get my vectors to be the same length. I am trying to use repmat to do this.
>
> I have three inputs of varying lengths
> 1) Latitude = 101
> 2) Longitude = 720
> 3) Depth = 40
>
> I am trying to use repmat to change the size of these vectors to 101x720x40 for my plot, but I can't seem to get it to work. When I use the repmat function for longitude:
>
> y2=repmat(lon,[1,720,40]);
> I get an output size 720x720x40. I can only use integers with repmat, but I don't see how I can get my output to be 101x720x40 without using a fraction.
>
> I'm sure I am just doing something stupid, but I would really appreciate some help.
>
> Thanks!
> Claire
- - - - - - - - - -
  What you need is 'ndgrid'. That puts the data in the "mesh" format required for 3D plots.

Roger Stafford

Subject: Repmat help

From: Claire

Date: 18 Sep, 2010 02:37:21

Message: 3 of 9

Thanks so much Roger!! I really appreciate the speedy reply!

Subject: Repmat help

From: Roger Stafford

Date: 18 Sep, 2010 02:49:07

Message: 4 of 9

"Claire " <claire.davis@students.mq.edu.au> wrote in message <i718l1$1iq$1@fred.mathworks.com>...
> Thanks so much Roger!! I really appreciate the speedy reply!
- - - - - - -
  After thinking of the matter more carefully, the advice I gave may not be appropriate to the problem as you described it. The purpose of scatter3 is to draw little markers (circles) at the x,y,z locations you give it, which means of course that there must be the same number of each type of coordinate. Can you please explain how this relates to the latitude, longitude, an depth inputs you have? If markers are to be placed at all 101*720*40 = 2,908,800 possible combinations of these values, then ndgrid would be called for, but that is a very large number of markers in a single "cube" plot. I suspect you have something very different in mind. Just where do you want markers placed in your scatter plot?

Roger Stafford

Subject: Repmat help

From: Claire

Date: 18 Sep, 2010 03:39:04

Message: 5 of 9

I am attempting to use scatter3 as the solution to a problem I posted on the website a few months ago:
http://www.mathworks.com/matlabcentral/newsreader/view_thread/286504

I didn't get any reply for that one so I am experimenting with scatter3 to see if it will do what I want.

Basically I have a 4D dataset (latitude, longitude, depth, time) that I want to create a 3D plot for (at one time - so it's really only 3D). I have density data contained within this 4D matrix that I am trying to plot.

Ideally, I want to produce a 3D plot of the density values within latitude, longitude and depth. The density matrix does not have values at all points, with NaNs filling in grid points that did not meet my criteria. So what that will hopefully mean is that I will be able to plot my density "blob" within 3D space. I am trying to show how a water mass is changing over time and I would like to be able to view that in 3D space.

Does that make sense?

Subject: Repmat help

From: Roger Stafford

Date: 18 Sep, 2010 04:11:08

Message: 6 of 9

"Claire " <claire.davis@students.mq.edu.au> wrote in message <i71c8o$brr$1@fred.mathworks.com>...
> I am attempting to use scatter3 as the solution to a problem I posted on the website a few months ago:
> http://www.mathworks.com/matlabcentral/newsreader/view_thread/286504
>
> I didn't get any reply for that one so I am experimenting with scatter3 to see if it will do what I want.
>
> Basically I have a 4D dataset (latitude, longitude, depth, time) that I want to create a 3D plot for (at one time - so it's really only 3D). I have density data contained within this 4D matrix that I am trying to plot.
>
> Ideally, I want to produce a 3D plot of the density values within latitude, longitude and depth. The density matrix does not have values at all points, with NaNs filling in grid points that did not meet my criteria. So what that will hopefully mean is that I will be able to plot my density "blob" within 3D space. I am trying to show how a water mass is changing over time and I would like to be able to view that in 3D space.
>
> Does that make sense?
- - - - - - - - - -
  That does not really answer the question I asked. Let's put it this way. Suppose for the sake of discussion you have just two input values of latitude, three of longitude, and four of depth. Out of these values how many little circle markers would you want to plot in scatter3, and what latitude, longitude, and depth would each of these 3D markers have? That is a very specific question and it deserved a specific answer. If you think about this question carefully I think you will see the difficulty other people might have understanding the problem you originally posed.

Roger Stafford

Subject: Repmat help

From: Claire

Date: 18 Sep, 2010 04:56:05

Message: 7 of 9

> - - - - - - - - - -
> That does not really answer the question I asked. Let's put it this way. Suppose for the sake of discussion you have just two input values of latitude, three of longitude, and four of depth. Out of these values how many little circle markers would you want to plot in scatter3, and what latitude, longitude, and depth would each of these 3D markers have? That is a very specific question and it deserved a specific answer. If you think about this question carefully I think you will see the difficulty other people might have understanding the problem you originally posed.
>
> Roger Stafford

Ok, So if I had 2x3x4 inputs then I potentially could plot circle markers at 24 locations within my 3D space. What I have done is created a matrix that has either a density value, or a NaN at all of those 24 locations. For example, lets say I have 4 locations within my 2x3x4 matrix that I want to plot a circle, with the other 20 locations being NaN, so no circle there.

Lets say the 4 points I want to plot are at;
(1,2,3)
(1,2,4)
(1,3,3)
(1,3,4)
So that there is a cluster of circles in one corner.

I hope this clarifies things.

Thanks!
Claire

Subject: Repmat help

From: Ross W

Date: 18 Sep, 2010 05:45:26

Message: 8 of 9

"Claire " <claire.davis@students.mq.edu.au> wrote in message <i71c8o$brr$1@fred.mathworks.com>...
> I am attempting to use scatter3 as the solution to a problem I posted on the website a few months ago:
> http://www.mathworks.com/matlabcentral/newsreader/view_thread/286504
>
> I didn't get any reply for that one so I am experimenting with scatter3 to see if it will do what I want.
>
> Basically I have a 4D dataset (latitude, longitude, depth, time) that I want to create a 3D plot for (at one time - so it's really only 3D). I have density data contained within this 4D matrix that I am trying to plot.
>
> Ideally, I want to produce a 3D plot of the density values within latitude, longitude and depth. The density matrix does not have values at all points, with NaNs filling in grid points that did not meet my criteria. So what that will hopefully mean is that I will be able to plot my density "blob" within 3D space. I am trying to show how a water mass is changing over time and I would like to be able to view that in 3D space.
>
> Does that make sense?

Here's an example - it might help.

lat=35:45;
lon=50:65;
depth=100:100:3000;
[lat1,lon1,dep1]=meshgrid(lat,lon,depth);
density=lat1+lon1+depth1/100; % just generating some bogus data

scatter3(lat1(:),lon1(:),depth1(:),10,density(:))

or else

k=5; % slice at every kth point along each axis
slice(lat1,lon1,depth1,density,lat(1:k:end), lon(1:k:end), depth(1:k:end))

all code written without testing - watch for bugs and typos.

Ross

see http://www.mathworks.com/help/techdoc/ref/slice.html

Subject: Repmat help

From: Roger Stafford

Date: 18 Sep, 2010 08:21:06

Message: 9 of 9

"Claire " <claire.davis@students.mq.edu.au> wrote in message <i71gp5$kvl$1@fred.mathworks.com>...
> Ok, So if I had 2x3x4 inputs then I potentially could plot circle markers at 24 locations within my 3D space. What I have done is created a matrix that has either a density value, or a NaN at all of those 24 locations. For example, lets say I have 4 locations within my 2x3x4 matrix that I want to plot a circle, with the other 20 locations being NaN, so no circle there.
>
> Lets say the 4 points I want to plot are at;
> (1,2,3)
> (1,2,4)
> (1,3,3)
> (1,3,4)
> So that there is a cluster of circles in one corner.
>
> I hope this clarifies things.
>
> Thanks!
> Claire
- - - - - - - - -
  You have just about answered the question you originally posed, Claire. In that hypothetical situation you should be sending scatter3 the three equal-length vectors:

 x = [1;1;1;1];
 y = [2;2;3;3];
 z = [3;4;3;4];

  In the actual problem with your 140 latitude values, 720 longitudes, and 40 depths, you will have to identify those combinations which are actually to be sent to scatter3. Just what is the best way of accomplishing this depends on what criterion you have for this selection. You spoke of NaNs being placed in combinations for which you have no density values. The ndgrid or meshgrid functions can create the full set of 140 by 720 by 40 combinations but from among all these you will have to somehow select only those for which there exists a corresponding density. In this selected set, of necessity there will be the same number of latitude, longitude, and depth values, just as in the above hypothetical case each quantity was given by a four-element vector.

  Below is a conceptual example of the above "selection". Out of all 40*44*48 = 84,480 possible combinations of the following x, y, and z values, there is selected a much smaller subset that belong to a certain doughnut-shaped ring. I counted 1,296 points that belong to this subset. It is supposed to be analogous to your set of combinations which possess a density.

 x = linspace(-1,1,40);
 y = linspace(-1,1,44);
 z = linspace(-1,1,48);
 [X,Y,Z] = ndgrid(x,y,z);
 X = X(:); Y = Y(:); Z = Z(:);
 t = (sqrt(X.^2+Y.^2)-.7)^2+Z.^2 <= .01; % <-- Inside the doughnut
 scatter3(X(t),Y(t),Z(t),markertype) % Use small markers

Roger Stafford

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