Dot indexing is not supported for variables of this type.

577 ビュー (過去 30 日間)
Pras
Pras 2021 年 5 月 26 日
コメント済み: Walter Roberson 2022 年 5 月 4 日
Dear all,
I am very new to Matlab. How can I fix the error of "Dot indexing is not supported for variables of this type" in the following code? Thank you.
global M_
% read out parameters to access them with their name
NumberOfParameters = M_.param_nbr;
for ii = 1:NumberOfParameters
paramname = deblank(M_.param_names(ii,:));
eval([ paramname ' = M_.params(' int2str(ii) ');']);
end
% initialize indicator
check = 0;
The error:
Dot indexing is not supported for variables of this type.
Error in DT_steadystate (line 7)
NumberOfParameters = M_.param_nbr;
Best,
Pras
  3 件のコメント
Walter Roberson
Walter Roberson 2022 年 5 月 4 日
I recommend against using importdata(), as the fundamental datatype that is output is too unpredicatable.
When you use importdata() with a file that is pure numeric after the given header lines, then the output is a pure numeric array.
But if you use importdata() with a file that has additional headers after the given header lines, then the output is a struct.
And if you use importdata() with a file that has a mix of text and numbers, then the output is a struct and the struct has additonal fields compared to the case of a header followed by pure numberic.
I recommand that you use readmatrix() instead for your situation.

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

採用された回答

Pras
Pras 2021 年 5 月 26 日
Thank you all for the reply. I am learning Matlab from this replication file of a journal article.
From another forum, I found that by including the following, it will work:
if isfield(M_,'param_nbr') == 1
end
Thanks!
Best,
Pras

その他の回答 (1 件)

Allen
Allen 2021 年 5 月 26 日
It appears that you are initializing a new variable M_ at the start of your code and by default it is just an empty double-class array. Doubles do not use or allow dot notation. Also, is there a reason why you are trying to initialize your variable as a global variable? If not, then I would recommend steering away from a global as this can create problems in subsquently run scripts if you are not careful.
clear
global M_
whos('M_')
Name Size Bytes Class Attributes M_ 0x0 0 double global
If you are intending for M_ to utilize the dot notation in MATLAB, then you will need to generate a table or structure class. See help documents for struct and table classes.
help struct
help table
  2 件のコメント
Allen
Allen 2021 年 5 月 26 日
Pras,
You should what you found as a solution to you question and accept your own response as the correct solution. This will help other people that are looking for a similar answer know what works.
Thanks,
Allen

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

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by