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

22 visualizzazioni (ultimi 30 giorni)
Hello,
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,
Christian
  1 Commento
Jiri Hajek
Jiri Hajek il 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?

Accedi per commentare.

Risposte (2)

Robert U
Robert U il 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,
Robert

Stephen23
Stephen23 il 23 Nov 2022
Modificato: Stephen23 il 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];
myplot(IWantThisNameInMyTitle)
function myplot(Y)
T = inputname(1);
plot(Y)
title(T)
end

Categorie

Scopri di più su Characters and Strings in Help Center e File Exchange

Prodotti


Release

R2022b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by