I am trying to take the values from the string "ind" following this logic:
ind = "i 1 1";
comp4 = strcmp(ind(1),"i")
if(comp4)
row = str2double(ind(3))
col = str2double(ind(5))
end
And for example the cond4 condition isn't validated, hence that's why I am asking why can't I take the values visualized of row and col.Thank you

 採用された回答

Fangjun Jiang
Fangjun Jiang 2023 年 3 月 10 日

0 投票

You got string array (" ") and char array( ' ') mixed. See which data format fits you better.
ind = "i 1 1"
ind = "i 1 1"
ind(1)
ans = "i 1 1"
ind2=char(ind)
ind2 = 'i 1 1'
ind2(1)
ans = 'i'

3 件のコメント

Caio Lorenzo Iriarte Salles
Caio Lorenzo Iriarte Salles 2023 年 3 月 10 日
Thank you!! I appreciate it
Fangjun Jiang
Fangjun Jiang 2023 年 3 月 10 日
Or split() it first
ind = "i 1 1";
split(ind," ")
ans = 3×1 string array
"i" "1" "1"
Steven Lord
Steven Lord 2023 年 3 月 10 日
Or use extractBetween.
ind = "i 1 1";
row = extractBetween(ind, 3, 3)
row = "1"
rowDouble = double(row)
rowDouble = 1
col = extractBetween(ind, 5, 5)
col = "1"
colDouble = double(col)
colDouble = 1

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

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File Exchange で Characters and Strings についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by