Getting data from the figure in appdesigner
Show older comments
Hi.
In my app, there is a section that lets user to select multiple points from a figure and later these points will be used to show some results. when I run this app in the matlab appdesigner space, everything works fine, However, when I complie the app by deploytool and create a standalone application,after installing the app and checking it, it doesn't save the selected points. in the picture, the top part is for when running the app within appdedesigner space and the bottom part is when I run it from the windows (after compiling and installing it on my compute). I am using the below code for getting information from a figure.
dcm_obj = datacursormode(fig);
set(dcm_obj,'DisplayStyle','datatip',...
'SnapToDataVertex','off','Enable','on')
pause
c_info = getCursorInfo(dcm_obj)
close gcf
I would really appreciate if anyone can tell me what should I do?

7 Comments
J. Alex Lee
on 4 Feb 2020
When you say "not saving", do you mean the app doesn't have access to the data, or do you mean not saving a file to disk?
Also, just in case, you are not trying to save data to the matlab workspace are you? I don't know how that would behave when deployed.
Arash
on 4 Feb 2020
J. Alex Lee
on 5 Feb 2020
Hmm, it seems unlikely that you're inadvertently sending to workspace...as far as I understand you'd need to be invoking assignin(c_info,'WS') or something like that...
So is your package route viable and/or your issue is solved?
J. Alex Lee
on 6 Feb 2020
Well, we never got to the actual code, but it sounds like you are maybe relying on external scripts rather than functions to do various tasks. Is this right? For example your supplied code snippet in your question is not wrapped in a "function" block? The same must be true for whatever block of code you are calling to do something with that data when you push the button. But this is odd because you're still able to access the separate figure in your deployed app...if you show your code, or at least the structure of your code, or the relevant chunks of code, this seems like it should be an easy problem to solve.
Arash
on 7 Feb 2020
J. Alex Lee
on 7 Feb 2020
I don't see anything wrong structurally, so I was wrong in my assumption.
Admittedly I don't know the getcursorinfo function, as it is in a toolbox I don't have, but I bet the problem is that nothing after calling "ManuallySelect()" is executing within your callback, either because of getCursorInfo itself, or how you are relying on pause().
I'm not sure if there's a better way using debug tools, but you can output something to console like
function ClickMePositiveButtonPushed(app, event)
%Getting the global variable displacement and force
y1=app.Displ;
y2=app.Force;
[x,y]=ManuallySelect(y1,y2);
disp('hi, checking if this executes!')
%saving it in the global propertise of the pp (DbackP and FbackP) to use it later
app.DbackP=x;
app.FbackP=y;
end
and try to catch it in your deployed app by running it via command line.
But yes, it would probably be cleaner to set up a way to respond to click callback's on the plotted object.
Answers (1)
J. Alex Lee
on 8 Feb 2020
2 votes
Here's an example where I used the data cursor's update function itself to collect the coordinates and feed directly into your app's DbackP and FbackP properties.
I think it should be easy enough to plug and play into your app.
Does it work?
3 Comments
Arash
on 10 Feb 2020
J. Alex Lee
on 10 Feb 2020
It looks like the offending line was "xline" and "yline", but you were actually able to open/run in your version of app designer otherwise. But I exported to .m as well. Does this work?
The important parts that we have been discussing are to pass the app to the ManuallySelect function so that it has direct access to the DbackP and FbackP properties
function results = ManuallySelect(app,xIn,yIn)
% clear the saved data?
app.DbackP = [];
app.FbackP = [];
app.UITable.Data = {};
app.DataFig = figure(); %'units','normalized','outerposition',[0 0 1 1]);
app.DataFig.CloseRequestFcn = @(src,evnt)CloseDataFig(app,src,evnt);
ax = axes(app.DataFig,'NextPlot','add','XGrid','on','YGrid','on'); % hold on
% if your matlab version supports
try
xline(0);
yline(0);
catch
% better than
plot([0 0],[-max(abs(Force)) max(abs(Force))],'k',[-max(abs(Displ)) max(abs(Displ))],[0 0],'k');
end
plot(ax,xIn,yIn,'LineWidth',1.1);
dcm_obj = datacursormode(app.DataFig);
set(dcm_obj,'DisplayStyle','datatip',...
'SnapToDataVertex','off','Enable','on')
dcm_obj.UpdateFcn = @(src,evnt)dateTipUpdateFcn(app,src,evnt);
end
And in define a new UpdateFcn for the dcm_obj that also has access to the app; in its callback function, keep appending new points and define the tooltip text
function txt = dateTipUpdateFcn(app,src,evnt)
app.DbackP = [app.DbackP;evnt.Position(1)];
app.FbackP = [app.FbackP;evnt.Position(2)];
txt = sprintf('saved point: (%g,%g)',evnt.Position);
app.UITable.Data = num2cell([app.DbackP,app.FbackP]);
end
Just for demo, I also had a uitable that was displaying all of the chosen data in real time.
Arash
on 10 Feb 2020
Categories
Find more on Develop Apps Using App Designer in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!