Reputation: 397
I have a .fig file that i want to modify just 2 values in x-axis.
How is it possible when i do not have the source code of plotting? There is just a .fig file.
Upvotes: 1
Views: 5265
Reputation: 112779
According to your comments: you have one pair of x- and y-axes, with several plots in it, and you want to modify the values.
Open the .fig file and do:
aux = get(gca,'Children'); %// get all plots within current axes
n = 1; %// or 2 or 3, whichever plot you want to change
x = get(aux(n),'XData'); %// x values of selected plot
This will give you the x-axis values in variable x
. Modify that variable as needed, and then put it back into the plot:
set(aux(n),'XData',x)
Upvotes: 2
Reputation: 30589
Pulling the data out with get(gca,...)
is probably the most direct solution. However, there is some other obscure but useful MATLAB functionality worth mentioning.
The first is the ability of MATLAB to generate M-files from figures, which can be used to recreate and modify a figure programmatically. Just click the following menu item and you will get a new function in the editor like function createfigure(X1, Y1)
that will exactly recreate the figure, but with some new data X1
and Y1
.
The other thing worth mention is that .fig files are really MAT-files containing data specifying the figure. For instance, the following commands will load the .fig data into a struct
in MATLAB and you can access the plot data easily:
>> f = load('testjunk.fig','-mat')
f =
hgS_070000: [1x1 struct]
>> axesNum = 1; seriesNum = 1;
>> series = f.hgS_070000.children(axesNum).children(seriesNum)
series =
type: 'graph2d.lineseries'
handle: 172.0051
properties: [1x1 struct]
children: []
special: []
>> X1 = series.properties.XData
ans =
0.0305 0.7441 0.5000 0.4799 0.9047
>> Y1 = series.properties.YData
ans =
0.6099 0.6177 0.8594 0.8055 0.5767
Mix and match to get the job done.
Upvotes: 1