659 views (last 30 days)
Show older comments
Pras on 26 May 2021
Commented: Walter Roberson on 7 Apr 2024 at 17:09
Accepted Answer: Pras
- DT_steadystate.m
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 Comments Show 1 older commentHide 1 older comment
Show 1 older commentHide 1 older comment
Walter Roberson on 26 May 2021
Direct link to this comment
https://uk.mathworks.com/matlabcentral/answers/840730-dot-indexing-is-not-supported-for-variables-of-this-type#comment_1544220
If you are new to MATLAB, you should pretend that eval() does not exist. eval() should only be used if there is no alternative.
http://www.mathworks.com/matlabcentral/answers/304528-tutorial-why-variables-should-not-be-named-dynamically-eval
Marwan Soliman on 4 May 2022
Direct link to this comment
https://uk.mathworks.com/matlabcentral/answers/840730-dot-indexing-is-not-supported-for-variables-of-this-type#comment_2140065
filename='pulse.txt';
delimiterIn='';
headerlinesIN= 1;
A=importdata(filename,delimiterIn,headerlinesIN);
Led_R = A.data(:,1); % RED (R)
Led_IR = A.data(:,2); % INFRARED (IR)
Dot indexing is not supported for variables of this type.
anyone can help plz line 5
Walter Roberson on 4 May 2022
Direct link to this comment
https://uk.mathworks.com/matlabcentral/answers/840730-dot-indexing-is-not-supported-for-variables-of-this-type#comment_2140835
@Marwan Soliman
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.
Sign in to comment.
Sign in to answer this question.
Accepted Answer
Pras on 26 May 2021
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
0 Comments Show -2 older commentsHide -2 older comments
Show -2 older commentsHide -2 older comments
Sign in to comment.
More Answers (2)
Allen on 26 May 2021
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 Comments Show NoneHide None
Show NoneHide None
Pras on 26 May 2021
Direct link to this comment
https://uk.mathworks.com/matlabcentral/answers/840730-dot-indexing-is-not-supported-for-variables-of-this-type#comment_1544250
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
Allen on 26 May 2021
Direct link to this comment
https://uk.mathworks.com/matlabcentral/answers/840730-dot-indexing-is-not-supported-for-variables-of-this-type#comment_1544285
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
Sign in to comment.
Tapamay on 6 Apr 2024 at 12:21
Hello Everyone,
I am 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.
The error shows this:
Dot indexing is not supported for variables of this type.
Error in RawData_To_CpVsAoA (line 13)
rawdata=rawdata.data(1:10,1:24);
clc; clear all; close all;
aoa=[-10 -8 -6 -4 -2 0 2 4 6 8 10 12 14 16 18 20 22 24 26 28 30];
Cp_aoa_data=[];
for i=1:length(aoa)
filename = ['Raw Data\',num2str(aoa(i)),'.txt'];
rawdata=importdata(filename);
rawdata=rawdata.data(1:10,1:24);
rawdata=mean(rawdata,1);
airfoilpressure=rawdata(1:22)*792*9.81/1000;
p_inf=rawdata(24)*792*9.81/1000;
p_0=-2.338*792*9.81/1000;
Cp = (airfoilpressure - p_inf)/(p_0-p_inf);
Cp_aoa_data=[Cp_aoa_data Cp'];
end
Error using importdata (line 139)
Unable to open file.
1 Comment Show -1 older commentsHide -1 older comments
Show -1 older commentsHide -1 older comments
Walter Roberson on 7 Apr 2024 at 17:09
Direct link to this comment
https://uk.mathworks.com/matlabcentral/answers/840730-dot-indexing-is-not-supported-for-variables-of-this-type#comment_3124056
The data type returned by importdata() depends on the format of the file. If it happened to be something that looked like a numeric block, then importdata() would return a numeric array, and numeric arrays do not allow dot indexing.
We recommend that you use readtable() or readmatrix() or readcell() instead of importdata()
Sign in to comment.
Sign in to answer this question.
See Also
Categories
MATLABData Import and AnalysisData Import and ExportStandard File Formats
Find more on Standard File Formats in Help Center and File Exchange
Tags
- dot indexing
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
An Error Occurred
Unable to complete the action because of changes made to the page. Reload the page to see its updated state.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- Deutsch
- English
- Français
- United Kingdom(English)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)
Contact your local office