MATLAB doesn't recognise a string in a variable

16 ビュー (過去 30 日間)
Lorenzo Chiarion Casoni
Lorenzo Chiarion Casoni 2015 年 7 月 25 日
コメント済み: Walter Roberson 2015 年 7 月 25 日
function q = edgeindex(edgenum, indexes, id)
length_index = length(indexes);
q = cell(1,edgenum);
b = 0;
for i = 1:length_index
l = indexes(i);
if i == 1
c = strsplit(id(l),'_');
b = b+1;
q{b} = l
else
d = strsplit(id(l),'_');
c{3}
d{3}
if srtcmp(c{3},d{3})
disp('equal')
q{b} = [q{b} (l)]
else
disp('not equal')
c = d;
b=b+1;
q{b} = l
end
end
end
end
Edgenum - an integer
Indexes - an array of integers
id - is a column vector made of text ex. OUT_218_46_[1][0].
At this point: c = strsplit(id(l),'_'); it gives me an error saying the first input has got to be a string. But it is a string? How do I overcome this problem?
I tried putting c = strsplit(char(id(l)),'_'); but a problem arises @ srtcmp(c{3},d{3})
Thanks in advance
  2 件のコメント
Arun Kumar
Arun Kumar 2015 年 7 月 25 日
id=OUT_218_46_[1][0];while l= 3(an integer) , id(l) gives 'T'.
Lorenzo Chiarion Casoni
Lorenzo Chiarion Casoni 2015 年 7 月 25 日
Sorry I meant to say, it's a column vector where each element is a string. These strings would be of format - 'OUT_218_46_[1]'.

サインインしてコメントする。

回答 (1 件)

Walter Roberson
Walter Roberson 2015 年 7 月 25 日
When you have a character array and you index it with a single numeric index, the result is a single character.
Column vectors of text are not considered strings: strings are row vectors of text.
Is is possible that id is a cell array of strings? If so then to extract the l'th entry you need id{l} rather than id(l) . This possibility is consistent with your error message.
  2 件のコメント
Lorenzo Chiarion Casoni
Lorenzo Chiarion Casoni 2015 年 7 月 25 日
You are right, I should change it to id{l}. But even so it gives me this error at the strcmp() - Undefined function 'srtcmp' for input arguments of type 'char'.
Walter Roberson
Walter Roberson 2015 年 7 月 25 日
strcmp() not srtcmp()

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeCharacters and Strings についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by