HELP eval - Undefined function 'eval' for input arguments of type 'cell'. - find structure (from workspace) with part of name and accessing it
Show older comments
Hello, I am currently writing a code to analyse blood pressure. The blood pressure has been extracted using another language, the code renamed my channels a bit weirdly. I just need to modify my matlab code to make it flexible to all those weird names .. and I am a bit stuck.
My matlab code is looped on my participants.
For each participant, I load a .mat file (easy).
As I said the channel are weirdly renamed :
name of channel1: XYPlot *1_01_1*__Ch1
name of channel2: XYPlot *1_01_1*__Ch2
name of channel3: XYPlot *1_01_1*__Ch3
The bold part is always different between subjects.
**MY GOAL
To define:
time_Spike= channel2.xvalues;
SBP_peaks_values = channel2.yvalues;
**MY SCRIPT
namesWorkspace = who;
outStr = regexpi(namesWorkspace, 'Ch2');
ind = ~cellfun('isempty',outStr);
var = namesWorkspace(ind);
str={var};
out=str{1};
channel2=eval(out);
time_Spike= channel2.xvalues;
SBP_peaks_values = channel2.yvalues;
**OUTCOME
But I have a problem with eval
"Undefined function 'eval' for input arguments of type 'cell'."
I am sure there is another easier way to do what I want to do,
Your help and feedback would be very appreciated :)
thanks
Sophie
1 Comment
Image Analyst
on 22 Jul 2017
Edited: Image Analyst
on 22 Jul 2017
Sophie, you forgot to attach the .mat file so I can't do anything (yet).
"out" appears to be the contents of a cell. We don't know what data type it is - it could be anything. But there is no reason to send in into eval(). Why did you do that???
Accepted Answer
More Answers (1)
Steven Lord
on 22 Jul 2017
1 vote
DON'T use eval. load your data into a struct array and use fieldnames and dynamic field names to access the data in the struct array.
Categories
Find more on Variables 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!