How modify some x-axis values in a .fig file in MATLAB?

折月煮酒 提交于 2019-12-13 18:16:57

问题


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.


回答1:


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.




回答2:


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)


来源:https://stackoverflow.com/questions/19741559/how-modify-some-x-axis-values-in-a-fig-file-in-matlab

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!