Extract data points in contour map - matlab

My data is xy rings with z as a height. I create a contour map of the data. I need to be able to create xy data points with the z component having a value somewhere between the 2 contour lines. Then extract all of the xyz data. I have found a few programs to extract the data but it is only x,y data and it is basically the xy data that I originally started with.

Related

Matlab: How to plot coordinate locations using x markers in a contour map?

I need to plot the locations of 3 treasures on a contour map.The coordinates are in a matrix (3x2) called "treasures", the first column contains the y coordinates, and the second column the x coordinates.
Using an X marker I was asked to plot the treasures locations using a marker size of 15, a line width of 4 and a red color.
How could I do that? the image should look like this
It looks like you need to read a basic tutorial on matlab first before you take on this project.
plotting scattered points can be done in matlab using the command plot. Assuming your treasure locations is x and y (both can be a vector for multiple points), you can plot those using
plot(x,y,'rx','markersize',15)

extract data points for the plot

I want to extract data points of a plot, but this plot is in a .jpg format. I converted it to the .fig but there are two curves in this plot and I don’t know how to do it.
How can I extract data points for the plot that I attach here?

Plotting arbitrary 3d finite element mesh with matlab

Hello guys I am trying to export a mesh from MSC Patran and then plot it in Matlab. The mesh can be of arbitrary shape. I have the x, y and z coordinates of all the nodes. So far I have tried many different options and here is why they failed:
Surfc() with meshgrid and griddata:
I generated a grid on x-y plane with meshgrid and then used griddata to obtain the z matrix. But this plot only works when there is only 1 z value corresponding to an x-y pair. In other words, for this to work z must be of type z = f(x,y).
pdegplot() : I found out that matlab can import and plot .stl files. I tried converting my coordinate matrix format and plot it with this function but it doesn't work either. Because apparently in .stl files an edge can not be shared by more than 2 elements. However my FEM files are always (i hope) shell elements. This means 3 or more elements can share the same elements.
Surfc() with 3d meshgrid: I found out that meshgrid() can take 3 inputs (x,y,z) and create a 3d mesh. However this didn't work either. I used a very small mesh with about 1000 nodes and the code was trying to generate 3 matrices with 1000x1000x1000 elements. That means about 3 gb of memory for a 1000 node mesh. Whats more, surfc couldn't plot even that.
Somehow importing other file formats automatically: so far I have been using patran neutral files (.out). I manually read the file and extract x,y,z data from it. Patran can also export to parasolid, iges and step file formats. I looked for direct ways of importing and plotting these in matlab but such functions don't exist as far as I have looked.
Manually generating a grid: Matlab can create 3D objects (like [x,y,z] = sphere()) and Surfc() can plot these despite what I said in (1.) and the x,y,z matrices generated by sphere() are not 3 dimensional like in (3.) so I tried following this and manually generate a 3d grid from my FEM file just for testing. I found that z has repeating columns and in each column (which acts as a layer) there are n values of x and y. When I tried doing the same thing for my mesh manually, surfc() didn't work again. It plotted a really weird shape that I can't even describe.
Finding a 3rd party plotting software: I tried using (light) software like gnuplot and visit but so far I am all wet. I am open to suggestions if you know any (preferably open source) software that can directly plot patran neutral files. But the software has to be capable of contour plotting also. As I am calculating a quantity for each node in Matlab and then plotting its contour on the mesh.
So you can have a tetramesh?
You seem to be working with FEM-stile meshes, thus the standard surface-plotting function wont work. For FEM-meshes of different shape (not tetra) you may need to write your own function...
If you have the grid points and grid cell connectivities in say variables p and c, you can use the external Matlab FEA Toolbox to plot both structured and unstructured grids with for example the plotgrid command
% Cread grid struct.
grid.p = p;
grid.c = c;
grid.a = gridadj(p,c,size(p,1)); % Reconstruct grid cell adjacencies.
grid.b = gridbdr(p,c,grid.a); % Reconstruct boundary information.
grid.s = ones(1,size(c,2)); % Set subdomain numbers to 1 for all grid cells.
% Plot grid.
plotgrid( grid )

Creating surface in matlab

I have a variable named say P which is simply a n*3 matrix. It stores x,y,z coordinates for a contour plot, its like a closed loop. Now I have several matrices like P which slice my object. What I would like is to create a surface using these contour points. scatter3() does not really give a good representation. The issue using surf() is that since I have contour coordinates, the coordinates are unordered. So the plot obtained using surf() is not the actual closed surface of my figure. How can I resolve this? Let's brainstorm.

annotated scatter graph matlab/octave

I have 25 pairs of (x,y) co-ordinates. Each of these pairs corresponds to a country. I want to plot the 25 points on a scatter graph, and have the country name for each point directly next to the point on the scatter graph. I can't figure out how to do this in MATLAB or Octave (I have both MATLAB and Octave and don't mind which I use, which is why I'm asking about both).
Let's say I put the (x,y) co-ordinates and corresponding country labels in a matrix of 25 rows and 3 columns, with the labels in the first column. Does anyone know the command I can use for the desired graph?
Strings don't play well with matrices, so I'm adjusting your storage format slightly. Here's the test data: a 25x2 matrix of coordinates, and a 25x1 cell array of strings.
p = rand(25,2);
names = repmat({'name'}, 25, 1)
You'll have to play with the offsets slightly, but here's the idea:
scatter(p(:,1), p(:,2))
%# Compute some offsets for the lower-left of the text box, based
%# on overall size of the plot
offset_x = diff(xlim) * .01;
offset_y = diff(ylim) * .01;
text(p(:,1)+offset_x, p(:,2)+offset_y, names)