How to Fix the “Dot indexing not supported for variables of this type” Error in MATLAB

101 views (last 30 days)
I am writing a code and i've tried to run it. However, it shows me an error saying "Dot indexing is not supported for variables of this type".
Dot indexing is not supported for variables of this type.
Error in SDE (line 38)
dataset = dataset.Train;
Any kind of help will be appreciated. Thank you.
dataset = load(['/Users/zachary/Desktop/MatlabCode/SDE-master/train/',p_name]);
dataset = dataset.Train;
feat = dataset(:,1:end-1);
labels = dataset(:,end);
  4 Comments
Dyuman Joshi
Dyuman Joshi on 5 Oct 2023
Edited: Dyuman Joshi on 5 Oct 2023
This is just a numeric text file. No headers or anything, just plain numbers. The output will be a numeric array when you read the data in the file with load.
Additionally, the input to load() does not contain the filename (including the extension). Why does it not?
And what are you trying to obtain from the data?
(Also, Are you related to Darth Vader? :P)

Sign in to comment.

Accepted Answer

dpb
dpb on 5 Oct 2023
Edited: Walter Roberson on 9 Oct 2023
That's just a plain text file; use readmatrix to bring it in as an array...
% first read as text to be certain of file structure -- lines are wrapped in browser
l=readlines('QSARbiodegradation.txt');
l(1:5)
ans = 5×1 string array
" 5.3030000e+000 4.0516000e+000 0.0000000e+000 0.0000000e+000 0.0000000e+000 1.0000000e+000 0.0000000e+000 2.6100000e+001 4.0000000e+000 3.0000000e+000 0.0000000e+000 0.0000000e+000 3.0100000e+000 1.3920000e+000 1.0053000e+001 9.0000000e+000 1.0070000e+000 1.1540000e+000 0.0000000e+000 0.0000000e+000 0.0000000e+000 1.0790000e+000 0.0000000e+000 0.0000000e+000 0.0000000e+000 0.0000000e+000 2.2360000e+000 4.4000000e-002 0.0000000e+000 0.0000000e+000 1.1640000e+000 0.0000000e+000 0.0000000e+000 0.0000000e+000 3.0000000e+000 3.3200000e+000 3.0280000e+000 0.0000000e+000 7.4530000e+000 0.0000000e+000 0.0000000e+000 2.0000000e+000" " 4.4990000e+000 2.9058000e+000 0.0000000e+000 0.0000000e+000 0.0000000e+000 0.0000000e+000 1.0000000e+000 4.3800000e+001 1.0000000e+000 1.0000000e+000 0.0000000e+000 0.0000000e+000 2.9900000e+000 1.1250000e+000 9.3110000e+000 2.0000000e+000 9.9100000e-001 1.1170000e+000 0.0000000e+000 0.0000000e+000 0.0000000e+000 1.2430000e+000 1.0000000e+000 0.0000000e+000 0.0000000e+000 0.0000000e+000 2.1360000e+000 4.4000000e-002 0.0000000e+000 0.0000000e+000 1.4810000e+000 0.0000000e+000 0.0000000e+000 0.0000000e+000 1.0000000e+000 3.5560000e+000 2.3960000e+000 0.0000000e+000 7.8450000e+000 0.0000000e+000 0.0000000e+000 1.0000000e+000" " 5.0130000e+000 1.8267000e+000 2.0000000e+000 1.0000000e+000 1.6000000e+001 0.0000000e+000 7.0000000e+000 4.2400000e+001 2.0000000e+000 5.0000000e+000 1.4000000e+001 -1.1230000e+000 4.6920000e+000 1.5410000e+000 1.1371000e+001 5.0000000e+000 1.0190000e+000 1.1210000e+000 0.0000000e+000 0.0000000e+000 0.0000000e+000 1.2770000e+000 5.0000000e+000 0.0000000e+000 1.0000000e+000 0.0000000e+000 2.4150000e+000 0.0000000e+000 0.0000000e+000 3.5613000e+001 4.3740000e+000 0.0000000e+000 4.0000000e+000 1.3000000e+001 1.0000000e+000 4.3040000e+000 2.4440000e+000 5.0000000e+000 9.9560000e+000 0.0000000e+000 1.0000000e+000 2.0000000e+000" " 4.9710000e+000 3.0393000e+000 0.0000000e+000 0.0000000e+000 2.0000000e+000 0.0000000e+000 2.0000000e+000 3.8700000e+001 3.0000000e+000 1.0000000e+000 2.0000000e+000 1.2400000e-001 3.5090000e+000 1.7330000e+000 1.0236000e+001 4.0000000e+000 9.8400000e-001 1.1300000e+000 0.0000000e+000 0.0000000e+000 0.0000000e+000 1.2510000e+000 1.0000000e+000 0.0000000e+000 0.0000000e+000 0.0000000e+000 2.3050000e+000 1.0000000e-003 0.0000000e+000 1.1885000e+001 2.5850000e+000 0.0000000e+000 0.0000000e+000 3.0000000e+000 0.0000000e+000 3.7250000e+000 2.2140000e+000 1.0000000e+000 8.4400000e+000 0.0000000e+000 0.0000000e+000 2.0000000e+000" " 5.3610000e+000 1.8900000e+000 0.0000000e+000 0.0000000e+000 2.0000000e+000 1.0000000e+000 0.0000000e+000 2.8900000e+001 2.0000000e+000 4.0000000e+000 2.0000000e+000 0.0000000e+000 3.7640000e+000 1.5910000e+000 1.0691000e+001 1.6000000e+001 1.0030000e+000 1.1510000e+000 0.0000000e+000 0.0000000e+000 0.0000000e+000 1.1320000e+000 2.0000000e+000 0.0000000e+000 0.0000000e+000 0.0000000e+000 2.4070000e+000 0.0000000e+000 0.0000000e+000 0.0000000e+000 3.2610000e+000 0.0000000e+000 0.0000000e+000 2.0000000e+000 4.0000000e+000 3.4950000e+000 2.1540000e+000 2.0000000e+000 8.3250000e+000 0.0000000e+000 0.0000000e+000 2.0000000e+000"
And, indeed, that is so..
data=readmatrix('QSARbiodegradation.txt'); % read the array
data(1:5,:)
ans = 5×42
5.3030 4.0516 0 0 0 1.0000 0 26.1000 4.0000 3.0000 0 0 3.0100 1.3920 10.0530 9.0000 1.0070 1.1540 0 0 0 1.0790 0 0 0 0 2.2360 0.0440 0 0 4.4990 2.9058 0 0 0 0 1.0000 43.8000 1.0000 1.0000 0 0 2.9900 1.1250 9.3110 2.0000 0.9910 1.1170 0 0 0 1.2430 1.0000 0 0 0 2.1360 0.0440 0 0 5.0130 1.8267 2.0000 1.0000 16.0000 0 7.0000 42.4000 2.0000 5.0000 14.0000 -1.1230 4.6920 1.5410 11.3710 5.0000 1.0190 1.1210 0 0 0 1.2770 5.0000 0 1.0000 0 2.4150 0 0 35.6130 4.9710 3.0393 0 0 2.0000 0 2.0000 38.7000 3.0000 1.0000 2.0000 0.1240 3.5090 1.7330 10.2360 4.0000 0.9840 1.1300 0 0 0 1.2510 1.0000 0 0 0 2.3050 0.0010 0 11.8850 5.3610 1.8900 0 0 2.0000 1.0000 0 28.9000 2.0000 4.0000 2.0000 0 3.7640 1.5910 10.6910 16.0000 1.0030 1.1510 0 0 0 1.1320 2.0000 0 0 0 2.4070 0 0 0
whos data
Name Size Bytes Class Attributes data 739x42 248304 double
No "dot" referencing needed (or allowed). If there are meaningful variable names for each column, then you could use those and either use array2table and assign those or go directly to the table with readtable. However, with 42 columns, it's probably not a particularly convenient data set to use named column variables...

More Answers (1)

Walter Roberson
Walter Roberson on 5 Oct 2023
load() of a .txt file never results in a struct or object so you cannot use dot indexing with it. (well, except if you use the -mat option and the .txt file happened to be mat file format)
load() of a .mat file stored to a file results in a struct -- but not of a .txt
importdata() of a .txt file results in a pure numeric matrix if the txt file has no text headers. But if it has text headers then importdata() can return a struct with a few different possible fields (that are not always going to be present.) Because of this variability in what data type impordata() can return, I recommend against using importdata()

Community Treasure Hunt

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

Start Hunting!