Effacer les filtres
Effacer les filtres

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

1 vue (au cours des 30 derniers jours)
Mat
Mat le 31 Oct 2014
Réponse apportée : Mat le 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 commentaires
Sara
Sara le 31 Oct 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 le 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.

Connectez-vous pour commenter.

Réponse acceptée

Mat
Mat le 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);

Plus de réponses (0)

Catégories

En savoir plus sur Characters and Strings dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by