MATLAB Answers

sara sar

How to store values in cell array?

Asked by sara sar
on 13 Oct 2018 at 11:25
Latest activity Edited by sara sar
on 14 Oct 2018 at 8:03

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?


Sign in to comment.

2 Answers

Answer by madhan ravi on 13 Oct 2018 at 11:33
Edited by madhan ravi on 13 Oct 2018 at 11:52

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


Show 1 older comment

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 I recommend that you use waitfor and simply return the values when the figure is closed:

function [A,B,C] = myGUI(...)
fgh = figure(...)
... Set A, B, C using nested callback functions

And then simply call it like any other function:

[X,Y,Z] = myGUI(...)

Thank you @stephen

Sign in to comment.

Answer by Image Analyst
on 13 Oct 2018 at 14:45
Edited by Image Analyst
on 13 Oct 2018 at 14:52

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.


Sign in to comment.