Can't use strcmp with two strings or char values that are apparently equal.
2 次查看(过去 30 天)
显示 更早的评论
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 个评论
回答(1 个)
Walter Roberson
2018-1-4
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.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Line Plots 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!