http://www.mathworks.com/matlabcentral/newsreader/view_thread/291811
MATLAB Central Newsreader  Repmat help
Feed for thread: Repmat help
enus
©19942015 by MathWorks, Inc.
webmaster@mathworks.com
MATLAB Central Newsreader
http://blogs.law.harvard.edu/tech/rss
60
MathWorks
http://www.mathworks.com/images/membrane_icon.gif

Sat, 18 Sep 2010 02:13:05 +0000
Repmat help
http://www.mathworks.com/matlabcentral/newsreader/view_thread/291811#780408
Claire
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. <br>
<br>
I have three inputs of varying lengths<br>
1) Latitude = 101<br>
2) Longitude = 720<br>
3) Depth = 40<br>
<br>
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:<br>
<br>
y2=repmat(lon,[1,720,40]);<br>
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. <br>
<br>
I'm sure I am just doing something stupid, but I would really appreciate some help. <br>
<br>
Thanks!<br>
Claire

Sat, 18 Sep 2010 02:23:05 +0000
Repmat help
http://www.mathworks.com/matlabcentral/newsreader/view_thread/291811#780409
Roger Stafford
"Claire " <claire.davis@students.mq.edu.au> wrote in message <i7177h$5t6$1@fred.mathworks.com>...<br>
> 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. <br>
> <br>
> I have three inputs of varying lengths<br>
> 1) Latitude = 101<br>
> 2) Longitude = 720<br>
> 3) Depth = 40<br>
> <br>
> 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:<br>
> <br>
> y2=repmat(lon,[1,720,40]);<br>
> 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. <br>
> <br>
> I'm sure I am just doing something stupid, but I would really appreciate some help. <br>
> <br>
> Thanks!<br>
> Claire<br>
         <br>
What you need is 'ndgrid'. That puts the data in the "mesh" format required for 3D plots.<br>
<br>
Roger Stafford

Sat, 18 Sep 2010 02:37:21 +0000
Repmat help
http://www.mathworks.com/matlabcentral/newsreader/view_thread/291811#780410
Claire
Thanks so much Roger!! I really appreciate the speedy reply!

Sat, 18 Sep 2010 02:49:07 +0000
Repmat help
http://www.mathworks.com/matlabcentral/newsreader/view_thread/291811#780412
Roger Stafford
"Claire " <claire.davis@students.mq.edu.au> wrote in message <i718l1$1iq$1@fred.mathworks.com>...<br>
> Thanks so much Roger!! I really appreciate the speedy reply!<br>
      <br>
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?<br>
<br>
Roger Stafford

Sat, 18 Sep 2010 03:39:04 +0000
Repmat help
http://www.mathworks.com/matlabcentral/newsreader/view_thread/291811#780415
Claire
I am attempting to use scatter3 as the solution to a problem I posted on the website a few months ago:<br>
<a href="http://www.mathworks.com/matlabcentral/newsreader/view_thread/286504">http://www.mathworks.com/matlabcentral/newsreader/view_thread/286504</a><br>
<br>
I didn't get any reply for that one so I am experimenting with scatter3 to see if it will do what I want. <br>
<br>
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. <br>
<br>
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. <br>
<br>
Does that make sense?

Sat, 18 Sep 2010 04:11:08 +0000
Repmat help
http://www.mathworks.com/matlabcentral/newsreader/view_thread/291811#780416
Roger Stafford
"Claire " <claire.davis@students.mq.edu.au> wrote in message <i71c8o$brr$1@fred.mathworks.com>...<br>
> I am attempting to use scatter3 as the solution to a problem I posted on the website a few months ago:<br>
> <a href="http://www.mathworks.com/matlabcentral/newsreader/view_thread/286504">http://www.mathworks.com/matlabcentral/newsreader/view_thread/286504</a><br>
> <br>
> I didn't get any reply for that one so I am experimenting with scatter3 to see if it will do what I want. <br>
> <br>
> 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. <br>
> <br>
> 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. <br>
> <br>
> Does that make sense?<br>
         <br>
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.<br>
<br>
Roger Stafford

Sat, 18 Sep 2010 04:56:05 +0000
Repmat help
http://www.mathworks.com/matlabcentral/newsreader/view_thread/291811#780422
Claire
>          <br>
> 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.<br>
> <br>
> Roger Stafford<br>
<br>
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.<br>
<br>
Lets say the 4 points I want to plot are at;<br>
(1,2,3)<br>
(1,2,4)<br>
(1,3,3)<br>
(1,3,4) <br>
So that there is a cluster of circles in one corner.<br>
<br>
I hope this clarifies things. <br>
<br>
Thanks!<br>
Claire

Sat, 18 Sep 2010 05:45:26 +0000
Repmat help
http://www.mathworks.com/matlabcentral/newsreader/view_thread/291811#780425
Ross W
"Claire " <claire.davis@students.mq.edu.au> wrote in message <i71c8o$brr$1@fred.mathworks.com>...<br>
> I am attempting to use scatter3 as the solution to a problem I posted on the website a few months ago:<br>
> <a href="http://www.mathworks.com/matlabcentral/newsreader/view_thread/286504">http://www.mathworks.com/matlabcentral/newsreader/view_thread/286504</a><br>
> <br>
> I didn't get any reply for that one so I am experimenting with scatter3 to see if it will do what I want. <br>
> <br>
> 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. <br>
> <br>
> 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. <br>
> <br>
> Does that make sense?<br>
<br>
Here's an example  it might help.<br>
<br>
lat=35:45;<br>
lon=50:65;<br>
depth=100:100:3000;<br>
[lat1,lon1,dep1]=meshgrid(lat,lon,depth);<br>
density=lat1+lon1+depth1/100; % just generating some bogus data<br>
<br>
scatter3(lat1(:),lon1(:),depth1(:),10,density(:))<br>
<br>
or else<br>
<br>
k=5; % slice at every kth point along each axis<br>
slice(lat1,lon1,depth1,density,lat(1:k:end), lon(1:k:end), depth(1:k:end)) <br>
<br>
all code written without testing  watch for bugs and typos.<br>
<br>
Ross<br>
<br>
see <a href="http://www.mathworks.com/help/techdoc/ref/slice.html">http://www.mathworks.com/help/techdoc/ref/slice.html</a>

Sat, 18 Sep 2010 08:21:06 +0000
Repmat help
http://www.mathworks.com/matlabcentral/newsreader/view_thread/291811#780433
Roger Stafford
"Claire " <claire.davis@students.mq.edu.au> wrote in message <i71gp5$kvl$1@fred.mathworks.com>...<br>
> 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.<br>
> <br>
> Lets say the 4 points I want to plot are at;<br>
> (1,2,3)<br>
> (1,2,4)<br>
> (1,3,3)<br>
> (1,3,4) <br>
> So that there is a cluster of circles in one corner.<br>
> <br>
> I hope this clarifies things. <br>
> <br>
> Thanks!<br>
> Claire<br>
        <br>
You have just about answered the question you originally posed, Claire. In that hypothetical situation you should be sending scatter3 the three equallength vectors:<br>
<br>
x = [1;1;1;1];<br>
y = [2;2;3;3];<br>
z = [3;4;3;4];<br>
<br>
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 fourelement vector.<br>
<br>
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 doughnutshaped 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.<br>
<br>
x = linspace(1,1,40);<br>
y = linspace(1,1,44);<br>
z = linspace(1,1,48);<br>
[X,Y,Z] = ndgrid(x,y,z);<br>
X = X(:); Y = Y(:); Z = Z(:);<br>
t = (sqrt(X.^2+Y.^2).7)^2+Z.^2 <= .01; % < Inside the doughnut<br>
scatter3(X(t),Y(t),Z(t),markertype) % Use small markers<br>
<br>
Roger Stafford