match a word/letter and add to the string cell - without a for loop
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hi, I would like to check for a letter in a cell string and if it matches the letter I would like to add a word or a sentence to the string eg:
Initial cell:
P etc etc etc
A etc etc etc
P etc etc etc
A etc etc etc
Final Cell
aaa P etc etc etc
A etc etc etc
aaa P etc etc ect
A etc ect ect
My appologies I know this is a horible example.
However, I would like to accomplish this without using a for loop. I've tried to use cellfun but I couldnt figure out how to do it. Thank you
4 commentaires
Sven
le 22 Août 2013
Yup, Vincent, I'll bet that if you can change your question so that you use actual code for your initialCell and finalCell, you'll have an answer returned within 10 minutes.
At the moment however your question is ambiguous because (for example) it's impossible to make a single cell look like the text you've provided for your finalCell, and it's not clear what your initialCell contents actually is.
Réponse acceptée
Jan
le 26 Août 2013
Modifié(e) : Jan
le 26 Août 2013
Unfortunately the contents of your data is still not clear, although there have been questions for clarifications.
If you have:
C = {'P etc etc etc'; ...
'A etc etc etc'; ...
'P etc etc etc'; ...
'A etc etc etc'}
This might help:
index = strncmp(C, 'P', 1);
C(index) = strcat('aaa', C(index));
But if you have a different input, please explain this preferably by adding valid Matlab code, which creates the data exactly. The original question is the best place for such details, so take the chance to edit it instead of hiding important details in comments.
0 commentaires
Plus de réponses (0)
Voir également
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!