Find a string from one cell, in a cell array of matrices

1 Ansicht (letzte 30 Tage)
Mat
Mat am 31 Okt. 2014
Beantwortet: Mat am 4 Nov. 2014
Been stuck on this step for a few hours now... And stumped.
My data is held in a cell array of matrices. I want to access these matrices, and search the cell number (30,2) in each of these matrices, then tell me which matrix the string was found in
I tried the following, I get :
for i=1:40 % loop through matrices in my cell array
find(strcmp(MyCellArray{1,i}(30,2),'MyString')) % find cell array location of string?
end
  2 Kommentare
Sara
Sara am 31 Okt. 2014
I don't understand how your data is arranged. It seems that MyCellArray is n by m cell array, with n = 1 and m = 40. What does each element contain? Another cell array? a string array? Attach it to the post.
Mat
Mat am 4 Nov. 2014
Sorry Sara, I hadn't realised you had commented, I normally get an email when an answer is sent... Each cell array element contained another cell array. The higher level cell array contained n=1 and m=40, and the lower levels contained variable rows and 19 columns.
I've eventually found a way to work it, which was:
for i=1:40
a = B{i}(30,2);
isthere{i}=strcmp(a,'mystring')
end
isthere2=cell2mat(isthere);
locationinB=find(isthere==1);
However I've actually scrapped this now in favour of another method.
Thanks for taking the time to comment and apologies I didn't reply until now.

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Mat
Mat am 4 Nov. 2014
This worked
for i=1:40
a = B{i}(30,2);
isthere{i}=strcmp(a,'mystring')
end
isthere2=cell2mat(isthere);
locationinB=find(isthere==1);

Weitere Antworten (0)

Kategorien

Mehr zu Characters and Strings finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by