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

1 次查看(过去 30 天)
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 个评论
Sara
Sara 2014-10-31
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 2014-11-4
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.

请先登录,再进行评论。

采纳的回答

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

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Characters and Strings 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by