Can't use strcmp with two strings or char values that are apparently equal.
8 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
I have a group of business days in format 'mm/dd/yyyy', from this, I created an array with a char format ( data_char) and a string format ( data_string). I have another much smaller group of dates also presented in two arrays with char ( date_vector_char) and string ( date_vector_str) formats. I want to know how many dates from the second group are present in the first group, and get their indices with a loop.
Without writing the loop, what I intend to do is this:
idx_1=find(strcmp(data_str,date_vector_str(1))==1);
idx_2=find(strcmp(data_char,date_vector_char(1))==1);
But the outcome is an empty array. When I hardcode a date value into the strcmp function, I get an index, but if I pick one value of my array, I get nothing.
Why is this? Can somebody help me? Thanks for your time.
0 comentarios
Respuestas (1)
Walter Roberson
el 4 de En. de 2018
I recommend that you switch to ismember instead of strcmp. Note the second output of ismember is the index of the element.
Meantime you might be having problems with nonprinting characters. Take the variable holding the character vector and add 0 to it in order to convert it to numeric and examine the numbers returned. Any number less than 32 is nonprinting and 32 is space. Some values from 127 to 159 are nonprinting. Values above that are a mix of printing and not. If you see any value above 127 then you probably were not expecting that.
Ver también
Categorías
Más información sobre Dates and Time en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!