MATLAB Answers

Jessica
0

Having Trouble Plotting 4D data

Asked by Jessica
on 17 Feb 2011
I'm a new user to Matlab so I'm hoping someone can help.
I have the data output from an atmospheric modeling program I am developing that I import into Matlab. The data is in the format x,y,z,value. The values represent pollution concentration in the atmosphere and the x,y,z are kilometer coordinates in the 3D region. I have tried the following code, but my plot ends up empty (but I do not get any error or diagnostic messages from the isosurface function). I got the mat & reshape ideas from another answer as a way to get my data into 3D arrays for the isosurface function:
EDU>> mat = [x(:) y(:) z(:) q_new(:)];
EDU>> mat = sortrows(mat,[3,1,2]);
EDU>> x = reshape(mat(:,1), [61 61 20]);
EDU>> y = reshape(mat(:,2), [61 61 20]);
EDU>> z = reshape(mat(:,3), [61 61 20]);
EDU>> q_new = reshape(mat(:,4), [61 61 20]);
EDU>> isovalue = 0.1671
isovalue =
0.1671
EDU>> isosurface(x,y,z,q_new,isovalue)
My values are quite small but I don't think that should make a difference, so I'm wondering if my data is too scattered or sparse and do I need to pre-process it in some other way to make it "plot-able"?
Any advice would be greatly appreciated. Thanks!

  2 Comments

Could you please format the code? One line per command, double space before the command, remove EDU>>.
Sorry about the formatting. I just cut and pasted and didn't realize it was joined up.
EDU>> mat = [x(:) y(:) z(:) q_new(:)];
EDU>> mat = sortrows(mat,[3,1,2]);
EDU>> x = reshape(mat(:,1), [61 61 20]);
EDU>> y = reshape(mat(:,2), [61 61 20]);
EDU>> z = reshape(mat(:,3), [61 61 20]);
EDU>> q_new = reshape(mat(:,4), [61 61 20]);
EDU>> isovalue = 0.1671
isovalue =
0.1671
EDU>> isosurface(x,y,z,q_new,isovalue)

Sign in to comment.

Products

5 Answers

Answer by Andrew Newell
on 17 Feb 2011

I don't see any obvious problem with the code, but of course I don't have the data. Maybe 0.1671 is outside the data range? You could try these commands to get some idea of how the data are distributed:
max(q_new(:))
min(q_new(:))
hist(q_new(:))
The isovalue represents a value of q_new, and isosurface tries to plot a surface separating values below isovalue and above - like contour, but for surfaces. If the points are scattered, it may be hard to define where that surface is. If your data are scattered (x,y, and z don't form a regular grid) TriScatteredInterp might help by moving the points to a regular grid. You might even want to apply smooth3 to the output.

  2 Comments

Not sure if I can add much to Andrew's explanation, but think of a weather map. Isobars are pressure contours. i.e. you measure pressure at a bunch of points at a given altitude, then join up the points with the same reading for pressure. Now imagine doing that at a bunch of altitudes. The isobars should morph slightly as you go from one height to another, so if you stacked all the weather maps on top of each other, the isobars would form a kind of cross-section/wireframe of a surface. (That's why I like to look at contours in slices.) In your case the surfaces would represent all the locations in space where the pollutant concentration was the given value (0.1671 or whatever).
As you can imagine, it's extremely difficult to make these surfaces by joining up all the same values if the data is sparse.
x, y, and z are a regular grid. The pollution concentration values I want to plot are varied and sparsely populate the grid at times (many points are 0 at times). I've tried TriScatteredInterp and now get something on the plot. Now I'm trying to determine if it is what I expect based on the data input. Thanks for the definition of isovalue. I couldn't find one anywhere in the documentation or the help.

Sign in to comment.


Answer by Matt Tearle
on 17 Feb 2011

I concur with Andrew about the code. Another diagnostic you could use is to visualize a series of slices:
figure
for k = 1:9
subplot(3,3,k)
[~,h] = contour(x(:,:,2*k),y(:,:,2*k),q_new(:,:,2*k));
set(h,'ShowText','on')
title(['z = ',num2str(z(1,1,2*k))])
end

  0 Comments

Sign in to comment.


Answer by Jessica
on 17 Feb 2011

0.1671 is the maximum value for q_new so it should be in range. I'll try the slices next.

  13 Comments

I totally agree.
Thanks for all your help. One last question before I send the data. I used the function TriScatteredInterp and I am now seeing a plot. Does that mean that my data was just too scattered to plot previously? Also, I was wondering what the isovalue variable is supposed to represent?
Yes, I think it would help. For clarity, I have added to my answer above.

Sign in to comment.


Answer by Matt Tearle
on 21 Feb 2011

Here's another possibility for looking at the sparsity of the data. You said many of the values were 0, so maybe try this:
idx = mat(:,4)>0;
figure
text(mat(idx,1),mat(idx,2),mat(idx,3),num2str(mat(idx,4)))
This will be hideously busy if there's a lot of nonzero data, but if not, it might give you a good idea of how spread the values are.
Similarly, you could also try plotting points where the pollutant concentration falls within a certain range. Something like
figure
idx = (mat(:,4)>0.1) & (mat(:,4)<0.12);
plot3(mat(idx,1),mat(idx,2),mat(idx,3),'o')

  1 Comment

this is great! while my data does not seem to display very well as an isosurface, when I plot it as points with the colors varying by value, it shows what I am trying to convey.
Thanks for all your help!

Sign in to comment.


Answer by Saeed68gm on 12 Apr 2011

Hello Jessica,
I am also new to MATLAB and I have a dataset that is similar to yours((x,y,z,value) for each point). The dataset is from a 3d scanner and it I want to show the data as a surface. for example this data is from a scanned gun, and I want to plot the gun surface( i figured using patch might be useful).
but i don't know how to use isosurface in this case. can you put a more sophisticated version of your code for me? I think you may have the solution to my problem...:)

  2 Comments

Please start a new question for this, and in that question specify whether your scan is over a regular grid or is scattered.
Ok, I already posted a new topic called Problem plotting 4D data.
Hope someone can help:)

Sign in to comment.