Save axes properties/data and load it on an other axes

9 ビュー (過去 30 日間)
Lilian Darracq
Lilian Darracq 2017 年 7 月 14 日
コメント済み: Walter Roberson 2017 年 7 月 14 日
Hello everyone,
I am currently working on a gui, in which among other things, i uses the google map API (via this function http://www.mathworks.com/matlabcentral/fileexchange/24113) and I have created several pushbutton allowing the user to modify the axes properties (zoom/pan...).
Now, because this API is supposed to be used on field tests, i need it to be able to work without an internet connection, and to do so i want the user to be able to save some maps beforehand, and load them when needed to. At first i thought that saving the XData/YData/CData of the figure would be enough, but it seems that it doesnt. I started with :
function saveMap_Callback(hObject, eventdata, handles)
children = findall(handles.axes1.Children, 'Tag', 'gmap');
XData = children(end).XData;
YData = children(end).YData;
CData = children(end).CData;
...
save(file, 'map');
But when i then try to load this and plot it with image(XData, YData, CData), it doesn't reproduce the same image, as the zoom properties are not 'stored' into the image data.
I then tried to also save the XLim and YLim of the axes, and only keep the corresponding part of the image :
limX = get(handles.axes1, 'XLim');
limY = get(handles.axes1, 'YLim');
mapX = (XData>limX(1)).*(XData < limX(2));
map.XData = XData(logical(mapX));
mapY = (YData>limY(1)).*(YData < limY(2));
map.YData = YData(logical(mapY));
map.limX = [map.XData(1) map.XData(end)] ;
map.limY = [map.YData(1) map.YData(end)];
map.CData(:,:,:) = CData(find(mapX,1, 'first'):find(mapX,1,'last'), find(mapY,1, 'first'):find(mapY,1,'last'), :) ;
Now the result is closer than what I want, but when i load the corresponding picture, the aspect ratio is clearly modified, and the picture is oddly stretched, even when i set the older XLim and YLim properties on the new axes.
The last step i wanted to do what to store the axes properties :
prop = get(handles.axes1)
And then, when i load the image, use it on my new axis :
image(XData, YData, CData);
set(handles.axes1, prop)
However, it triggers a bunch of errors as lots of the axes properties (CurrentPoint, etc...) are read-only ready.
So my questions are the following :
  • Is it possible to get only the non-read-only properties of the axes and use for another axes ?
  • Or even, is there better way to do what i want to do that i did not think of ?
Cheers, Lilian

採用された回答

Walter Roberson
Walter Roberson 2017 年 7 月 14 日
modifiiable_axes_fields_names = fieldnames( set(handles.axes1) );
  2 件のコメント
Lilian Darracq
Lilian Darracq 2017 年 7 月 14 日
Looks like the trick indeed, one last question though !
When i do this, some of the corresponding fields are empty, and thus i get some errors if i try to use it as new properties for my axes.
I am not entirely familiar with struct and structfun, but i am trying to do something like :
propTemp = set(handles.axes1);
prop = propTemp(~structfun(@isempty, propTemp))
However, structfun(@isempty, propTemp) is a logical array, so propTemp(~structfun(@isempty, propTemp)) throws an error.
How can i use this logical array to remove the empty fields in propTemp ?
Thanks a lot !!
Walter Roberson
Walter Roberson 2017 年 7 月 14 日
rmfield() can take a cell array of character vectors.
... But personally if I had a saved axes structure, then I would just copyobj() it, and then make whatever changes were appropriate to the copy (e.g., different Position)

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeCreating, Deleting, and Querying Graphics Objects についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by