How to Fix the “Dot indexing not supported for variables of this type” Error in MATLAB
72 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Aedy Vader
am 5 Okt. 2023
Bearbeitet: Walter Roberson
am 9 Okt. 2023
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 Kommentare
Dyuman Joshi
am 5 Okt. 2023
Bearbeitet: Dyuman Joshi
am 5 Okt. 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)
Akzeptierte Antwort
dpb
am 5 Okt. 2023
Bearbeitet: Walter Roberson
am 9 Okt. 2023
% first read as text to be certain of file structure -- lines are wrapped in browser
l=readlines('QSARbiodegradation.txt');
l(1:5)
And, indeed, that is so..
data=readmatrix('QSARbiodegradation.txt'); % read the array
data(1:5,:)
whos data
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...
0 Kommentare
Weitere Antworten (1)
Walter Roberson
am 5 Okt. 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()
0 Kommentare
Siehe auch
Kategorien
Mehr zu Text Files finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!