How to store values in cell array?
显示 更早的评论
I made a GUI that allows the user to determine regions in an image by using ROI object. the ROI object return its position as a matrix. I want to save the positions in a cell array when ever the user determine region in the image.
How can I do that?
回答(2 个)
madhan ravi
2018-10-13
编辑:madhan ravi
2018-10-13
An example:
A = {rand(4)} %stores the matrix as a cell array if you use curly braces
you can access the elements like a normal one
A{1}(1,1) %first element is obtained
6 个评论
sara sar
2018-10-13
madhan ravi
2018-10-13
Use the option mat2cell(rand(4))
"... it works but the result appears only in command window. It did not change in the workspace"
There is no such thing as the workspace: there is the base workspace and all functions (e.g. GUI's and callbacks) have their own independent workspaces:
If you want to return those values from a GUI to the base workspace then I recommend that you use waitfor and simply return the values when the figure is closed:
function [A,B,C] = myGUI(...)
...
A=[];B=[];C=[];
fgh = figure(...)
... Set A, B, C using nested callback functions
waitfor(fgh)
end
And then simply call it like any other function:
[X,Y,Z] = myGUI(...)
madhan ravi
2018-10-13
Thank you @stephen
sara sar
2018-10-15
@sara sar: if you want to pass data between callback function then use guidata (if you are unfortunately using GUIDE) or use nested functions (if you are happily writing your own GUI):
Note that callback functions do not return any output arguments, so there is no point in defining varargout.
If you want to return data from the GUI to the base workspace then either follow what I explained in my last comment, or if you are using GUIDE then use the OutputFcn:
Note that you can use waitfor inside the OutputFcn.
Image Analyst
2018-10-13
编辑:Image Analyst
2018-10-13
0 个投票
You don't need a cell array. See attached demo.
The best way to save the coordinates of a segmented image is as a binary image, or as boundaries (after using bwboundaries()).
You can use imwrite() to save the binary image in a .PNG disk file, or use save() to save the boundaries in a .mat file on disk if you need to.
4 个评论
sara sar
2018-10-15
Image Analyst
2018-10-15
OK, but not in a cell array. What would you put in the cell(s)? The binary image? The coordinates? Since you'd already have the variables to put into the cell (like you think you'd want), then why use an additional variable of a cell array? Just use the variables themselves and skip the cell array.
sara sar
2018-10-16
Image Analyst
2018-10-16
See my attached spatial calibration demo.
类别
在 帮助中心 和 File Exchange 中查找有关 Image Arithmetic 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
