comparing strings
Mostrar comentarios más antiguos
i have set of values,
A=[1:1:80]
B=1
now i want to convert into strings and then compare,if the values are same it should display 1 else 0
5 comentarios
Oleg Komarov
el 21 de En. de 2012
http://www.mathworks.com/matlabcentral/answers/6200-tutorial-how-to-ask-a-question-on-answers-and-get-a-fast-answer
Walter Roberson
el 21 de En. de 2012
Why bother converting to string when you could compare the numeric value?
kash
el 22 de En. de 2012
Walter Roberson
el 22 de En. de 2012
Yes? And why does that require comparing as strings instead of as numeric values?
Jan
el 22 de En. de 2012
How can 2 values be equal, if B is only a scalar? Is A not necessarily unique?
Respuestas (1)
Walter Roberson
el 23 de En. de 2012
for K = 1 : length(A)
results(K) = 0 + strcmp(num2str(A(K)), num2str(B));
end
I still think this is not good programming practice, but you asked and here it is.
Categorías
Más información sobre String Parsing en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!