Using if with char
Afficher commentaires plus anciens
I have a string being read on a line by line basis which is working fine. Then I check for the $PSIMTPP string and subsequently store this as recordsraw. The string comes in a comma delimited format and I need to check for the third colum. If the third column is either a B C or M I need to store the string. There is another parts of the code that stores a log(loggedsets) but this is working so.
tpp = strfind(sample, '$PSIMTPP')
if tpp == 1
log(loggedsets).recordsraw(index).tpp = textscan(sample, '%s %s %s %s %n %s %s %n %n %n %n', 'delimiter',',');
if strcmp(log(loggedsets).recordsraw(index).tpp{:,3}, 'B')
log(loggedsets).recordsb(index).tpp = log(loggedsets).recordsraw(index).tpp
elseif strcmp(log(loggedsets).recordsraw(index).tpp{:,3}, 'C')
log(loggedsets).recordsc(index).tpp = log(loggedsets).recordsraw(index).tpp
elseif strcmp(log(loggedsets).recordsraw(index).tpp{:,3}, 'M')
log(loggedsets).recordsm(index).tpp = log(loggedsets).recordsraw(index).tpp
end
index = index + 1
end
When I run this code everything works fine and I create the vectors I need but with one small problem. So for example in the string I have I have one B followed by 200 M and 200 C. The program creats 400 recordsm and 400 recordsc which are half empty.
I know its something to do with the if ifelse loop populating empty fields but not sure how to ammend?
Any ideas?
Réponses (1)
Craig
le 6 Mai 2014
Catégories
En savoir plus sur Characters and Strings 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!