function 'subsindex' is not defined for values of class 'string'
10 ビュー (過去 30 日間)
古いコメントを表示
Mattijs Mientki
2018 年 6 月 21 日
コメント済み: Bachtiar Muhammad Lubis
2018 年 12 月 20 日

This is roughly my code Only sometimes I have less or more inputs in the array "nam" In some situations i get the error " 'subsindex' is not defined for values of class 'string'" I looked for this, but could not find it and I do not understand what the error message means.
nam = ["t1" , "t3" , "t4"];
for j=1:3
figure
title( ['title start' nam(j) ] )
end
5 件のコメント
Geoff Hayes
2018 年 6 月 21 日
編集済み: Geoff Hayes
2018 年 6 月 21 日
Mattijs - is nam always an array or can it just be a string (in your code)? For example, if you have
someString = "hello";
someString(1)
What happens? Unfortunately, my version of MATLAB doesn't support creating strings (as opposed to character arrays) so I am wondering if, in some cases, your nam is just a string and not an array of strings and so treating the string object as if it were an array (using nam(j)) generates the error...
採用された回答
Steven Lord
2018 年 6 月 21 日
Rename the variable named title in your workspace so you can use the title function again.
When the error message refers to subsindex, it means you're trying to use an object as the index into a variable but MATLAB doesn't know how to interpret that object as an index and the variable into which you're trying to index hasn't had its indexing implemented to handle that situation.
In your case, you've done something like this but with potentially many lines between the first and second line of my example (so you forgot you created a variable named title) and with title instead of f as the name.
>> f = (1:10).^2;
>> f("5")
Function 'subsindex' is not defined for values of class 'string'.
4 件のコメント
Steven Lord
2018 年 12 月 16 日
Correct. You intend to call a function, but because you have a variable with the same name as the function and variables are higher precedence than functions MATLAB treats that code as an attempt to index into the variable.
Bachtiar Muhammad Lubis
2018 年 12 月 20 日
ow "variables are highers precedence than function" thanks a lot steven lord.
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Matrix Indexing についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!