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

22 ビュー (過去 30 日間)
Christian Bundschu
Christian Bundschu 2022 年 11 月 23 日
編集済み: Stephen23 2022 年 11 月 23 日
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 件のコメント
Jiri Hajek
Jiri Hajek 2022 年 11 月 23 日
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?

サインインしてコメントする。

回答 (2 件)

Robert U
Robert U 2022 年 11 月 23 日
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 2022 年 11 月 23 日
編集済み: Stephen23 2022 年 11 月 23 日
"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

カテゴリ

Help Center および File ExchangeCharacters and Strings についてさらに検索

製品


リリース

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by