I drew a mesh in Matlab. The data for the mesh was supplied with a filled 3d Matrix. Nothing special with that.
I saved the created figure and came back to it now.
I want to create a different plot with the same data. Is there a way to extract the matrix data from the mesh so I can reuse it?
With some luck, following solution could work:
Load the figure file:
fig = openfig('fig_file_name.fig');
Get the surface data from the axes of the figure (assuming surface is the first "children"):
s = fig.CurrentAxes.Children(1);
Look for your data in s.XData, s.YData and s.ZData.
Better solution is using findobj (instead of fig.CurrentAxes.Children(1)) use:
s = findobj(fig, 'type', 'Surface');
Related
I have a 24 dimensional dataset of 100,000 data points which are mapped onto 2d plane using sammon mapping (a method ro reduce dimensionality and visualize). The scatter plot is shown below! Doesn't look too interesting..
But when i tilted my screen an looked at the figure, a square array of points appeared. I am not a matlab user and i am confused whether there is some meaning
to this for example are the points forming a clusters etc ? or is this just some sorcery.
Please use the scatter command and change the scatter properties.
fig = figure('Color','white');
sc = scatter(y_stacked(:,1), y_stacked(:,2));
sc.Marker = '.';
sc.SizeData = 1;
Then, make the figure window as big as possible and/or zoom in to examine your data points more closely.
I use function pcolor3 to draw a volume rendering result like the following one.
And I want to plot a base map:
The question is I can do the two images separately. But when I combine them together, both of them are missing:
Can anyone help me find a solution? Thanks.
Sorry for not attaching the code. Here it is.
#data is a 3d matrix. S is a shapefile.
[X,Y,Z]=meshgrid(xgr,ygr,zgr);
S = shaperead(filename);
hold on;
pcolor3(X,Y,Z,data); # show the 3d matrix
mapshow(S,'FaceColor',[0.5 0.5 0.5]); # show the base map
hold off;
I'm not sure if the problem is in function mapshow. When I use mapshow in a 3d scatterplot, it is good. However, this time, it's bad.
I´m facing a problem. I open a figure-file (.fig) in Matlab that is a 2D contourf-plot. I created the file with a software that is based on matlab but has a GUI: maptools. I added Isolines in the plot. Each Isoline is labeled by me (clabel in matlab). The problem now is that I can´t set the space between the labels of the isolines so that each isoline has a lot of labels say for example 5.
in Matlab it is pretty easy to fix that. just the following way:
[Cp hp] = contourf(x,y,levels);
clabel(Cp,hp,'LabelSpacing',150);
My Question now is whether it is possible to read in the figure-file in Matlab with openfig(anyfigure.fig) and change the space between the isoline labels. In other words, is there any isoline (or isoline label) handle for a figure file that is opened with openfig()
Thank you ;)
When you use contour/contourf you are generating instances of a contour object that you can address directly. When loading in your figure, specify an output so you have the handle to your figure, which you can use with findobj to locate your contour object. This contour object is the second input to clabel.
For example:
filepath = 'somepath';
myfig = openfig(filepath);
# Assume only one contour object in the figure
hp = findobj(myfig.Children, 'Type', 'contour');
clabel([], hp, 'LabelSpacing', 150);
Which generates the following for a sample contour plot:
Note that clabel, per the documentation, does not need the contour matrix input C if you have the handle to the contour object. The contour matrix is a property of the object so MATLAB can get it for itself.
I have got a data of size 13558x100 and I am trying to plot it. For 2D, I could use:
plot(X(:,1), X(:,2))
How can I plot this big data? Can I just use surf to visualize the data or is there any other way?
As others have mentioned imagesc is the better way to go about this. It allows you to see a field of 2D data without a 3D plot using colour mapping. The toy example code is here.
Y = randn(13558,100);
figure; imagesc( Y );
This code generates the image as follows.
Furthermore, you can use the function colorbar to get a bar legend for your data.
colorbar;
After using the colorbar function, it generates the figure below.
I have some sparse data and want to plot them as markers connected by a smooth, interpolated line - like the default behaviour of Microsoft Excel.
There are solutions to this problem easily found on the internet, but I find them unsatisfactory. What they do is: plot the sparse data as one data set drawing it as markers without lines, interpolate it with a method of choice and plot the interpolation as the second data set, with lines without markers.
The problem with these tricks is that in the legend the two data sets will be listed separately. I would expect a single data set depicted in the legend as a line crossing through a marker.
Is it possible in Matlab?
If you want to plot an interpolated line there are lots of ways to do that. You can try generating an interpolated line using the matlab interp1() function.
Let's create x and y data with no NaN.
x = randn(1,10)
y = randn(1,10)
If you want 1000 data points where previously you only had a few, that's pretty easy:
x2 = min(x):(max(x)-min(x))/1000:max(x)
y2 = interp1(x,y,x2,'cubic')
and you can plot your data and spline using
plot(x,y,'r+')
hold on
plot(x2,y2,'r-')
A custom legend is straightforward when you use handle graphics. You can plot a dummy data set with a red line passing through a marker using
h(1) = plot(NaN,NaN,'r-+')
lstring{1} = 'Data';
You can then add a legend that points to this data set using
legend(h,lstring)
You'll end up with something that looks roughly like this:
The nice thing about using handle graphics (i.e. the h) is you can throw whatever data series you want into the legend as h(end+1) and lstring{end+1}.