Extracting the name of my cell array to use for figure titles

5 views (last 30 days)
I have been searching for quite a while for a method to take the name of my cell and print it as the title of a plot.
For example: I have a 5x1 cell array named BeadsAll where each cell contains data from a different experiment trial. I want to throw the cell array BeadsAll into a function I have made that cleans, organizes, and plots the trial data and then properly titles it with respect to the cell array it is contained in.
Since I have a number of different cell arrays other than the "BeadsAll" that I want to use this function for, the title of the plots needs to reflect the cell array that is being called and evaluated.
I have heard that the "eval" function is not the way to go - and frankly - I'm still confused on how it's used even after looking at the documentation and forums.
Some guidance on a function I have overlooked or a process I can embed into my function that will convert the handle of my cell array to usable string for naming purposes would be really appreciated!
Thank you so much,
  1 Comment
Jiri Hajek
Jiri Hajek on 23 Nov 2022
Hi, this should be fairly easy to accomplish. To give you an answer however, please first describe how you store the names of your cell arrays? The name "BeadsAll" and alike are read from a file or generated dynamicaly?

Sign in to comment.

Answers (2)

Robert U
Robert U on 23 Nov 2022
Hi Christian Bundschu,
Have a look for structure arrays (struct()). With structure arrays you can manage your cell arrays not as single variables but as structure. It becomes handy in processing the cell arrays that could be stored as multiple fields with meaningful names.
You can read fieldnames with the command fieldnames() plus it is possible to name and address fieldnames dynamically (Generate Fieldnames from Variables).
Kind regards,

Stephen23 on 23 Nov 2022
Edited: Stephen23 on 23 Nov 2022
"Some guidance on a function I have overlooked ..."
Using EVAL() is a red-herring, and is very unlikely to help you with this task.
IWantThisNameInMyTitle = [1,4,6];
function myplot(Y)
T = inputname(1);


Find more on Structures 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!