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

조회 수: 23 (최근 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 CenterFile Exchange에서 Characters and Strings에 대해 자세히 알아보기

제품


릴리스

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by