MATLAB Answers

how to export figure data into a .mat file

69 views (last 30 days)
A
A on 6 Jun 2012
X=[0:.1:10];
Y=rand(length(X));
plot(X,Y)
is there a way to add a menu item to the figure window to save data (X,Y) into a file (have the user specify file name and location when they click on this menu item)

  0 Comments

Sign in to comment.

Accepted Answer

Walter Roberson
Walter Roberson on 6 Jun 2012
You can use uicontextmenu() to create a context menu, and you can set that to be the UiContextMenu property of an object such as an axes (and of anything else on the axes that you want to be independently clickable for other reasons, as context menus are sensitive to context)
Probably more often one would create a uicontrol('style','pushbutton') to do the work.
Use uiputfile() to have the user select a suitable output file.

  0 Comments

Sign in to comment.

More Answers (1)

Thomas
Thomas on 6 Jun 2012
In the figure gui click..
File>Save Workspace As..>'Any filename'

  1 Comment

A
A on 6 Jun 2012
the figure is generated within a function so it does not exist in the workspace

Sign in to comment.