How can I find a corresponding data value to a text value?
Show older comments
I read an Excel file which contains text and numerical data. It looks like this:

For each trial I have to see whether there is a looking ('yes') and eventually add up the durations of all the yesses for each trial.
I found the correct trial with the following code:
T = readcell(BehDataParticipant2);
T_trial1 = strcmp(T, 'Trial 1');
It resulted in zeros and ones throughout the whole table. But now I don't know how to find a 'yes' and the corresponding duration in those corresponding rows. Can you help me? Thanks!
Accepted Answer
More Answers (1)
Create the masks only over the relevant columns. Then use a logical combination of the masks to select the entries from the first column.
T = {1180, 'Trial 1', 'yes';
1150, 'Trial 1', [];
860, 'Trial 1', 'yes';
1350, 'Trial 2', 'yes';
940, 'Trial 2', 'yes'};
maskt1 = strcmpi(T(:,2),'trial 1');
maskt2 = strcmpi(T(:,2),'trial 2');
maskyn = strcmpi(T(:,3),'yes');
maskedvalues1 = cell2mat(T(maskt1 & maskyn,1))
maskedvalues2 = cell2mat(T(maskt2 & maskyn,1))
1 Comment
Quinty van der Heijden
on 9 Feb 2022
Edited: Quinty van der Heijden
on 9 Feb 2022
Categories
Find more on Tables 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!