MATLAB Answers

Ajpaezm
0

Can't use strcmp with two strings or char values that are apparently equal.

Ajpaezm
さんによって質問されました 2018 年 1 月 4 日
最新アクティビティ Ajpaezm
さんによって コメントされました 2018 年 1 月 5 日
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 件のコメント

サインイン to comment.

タグ

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.

  1 件のコメント

Ajpaezm
2018 年 1 月 5 日
I tried another approach, since I couldn't implement what you told me here.
I used datenum and transformed all dates to numeric format and then used find. It worked nicely.

サインイン to comment.



Translated by