String Vector for-loop
Afficher commentaires plus anciens
I recently collected some point data, and the trial number or independent variable is a string, such as:
X = ['a1' 'a2' 'a3' 'b1' 'b2' 'b3'];
I would like to create a for loop using the [1 2 3 1 2 3]. Is there any way to seperate the number and letter, or a way to us a string such as this as a for loop condition.
I do not want to use the index, and am trying to make this work for a much larger set of data, so I am trying to have it work automatically.
3 commentaires
Adam
le 29 Août 2019
Do you really mean a string or a char? What you show just evaluates as
'a1a2a3b1b2b3'
with all the individual quotation marks irrelevant. Is that what you actually have?
X = ["a1" "a2" "a3" "b1" "b2" "b3"];
would be a string array, or
X = ['a1'; 'a2'; 'a3'; 'b1'; 'b2'; 'b3'];
would give you a char array from which extracting the numbers is simply a case of taking the 2nd column, if all letters and numbers will be, as in your example, no longer than a single character long each.
zachary schneider
le 29 Août 2019
Adam
le 29 Août 2019
So simply
str2num( X(:,2) )
would give what you want.
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Logical dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!