Filter löschen
Filter löschen

Error : Dot indexing is not supported for variables of this type.

21 Ansichten (letzte 30 Tage)
Dhaval
Dhaval am 9 Okt. 2023
Beantwortet: Gyan Vaibhav am 18 Okt. 2023
function signal_matrix = read_txt(~,file_path) % read text
filename=file_path;
the_whole_text=importdata(filename,' ');
title_name = '';
type_of_the_test = '';
for i = 1: length(the_whole_text.textdata)
if ~isempty(strfind(char(the_whole_text.textdata(i)),'Title'))
title = char(the_whole_text.textdata(i));
title_name = title(30:end);
end
if ~isempty(strfind(char(the_whole_text.textdata(i)),'Type of the test'))
type_of_test = char(the_whole_text.textdata(i));
type_of_the_test = type_of_test(30:end);
end
end
end
I am using this function to import data in matlab workspace but i am getting error like dot indexing is not supporting for this variable. Could anyone know how to solve ir?
  4 Kommentare
Rik
Rik am 9 Okt. 2023
This code looks like it is extremely fragile and expects an exact format. That doesn't have to be a problem, but it also doesn't have any documentation explaining the requirements.
It also doesn't have any comments explaining what this code should be doing and why. Without comments and documentation, this code is virtually useless, especially when any error occurs.
Dyuman Joshi
Dyuman Joshi am 9 Okt. 2023
Bearbeitet: Dyuman Joshi am 9 Okt. 2023
Please copy and paste the whole error message i.e. all of the red text.
What is the format of the data you are trying to import using importdata? Better to use alternate efficient functions and avoid importdata as Stephen23 mentions.

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Gyan Vaibhav
Gyan Vaibhav am 18 Okt. 2023
Hi Dhaval,
I noticed that you haven't provided a sample file or specified the type of file you are trying to read. Based on this, I can suggest two possible reasons for the issue you are facing.
If you are importing Excel files with formats like ".CSV" or ".XLSX", you need to remove the delimiter, " ", from the "importdata" line. The correct code should be:
the_whole_text = importdata(filename);
On the other hand, if you are importing text files that contain tables with values separated by spaces (" "), please ensure that the values are indeed separated by spaces. Alternatively, you can select the delimiter (the gap between two separated words) in the text file and replace all (Ctrl + H) with a space (" ") to be certain.
The error you are encountering is due to incorrect implementation of the "importdata" function. If the function were working as you expected, it would have returned a struct named "the_whole_text". However, in the current scenario, you are receiving a cell array that does not support dot (.) notation.
You can refer to the struct and cell array documentation pages linked below:
While these are not the only possible reasons for the issue, I recommend trying these fixes and consulting the documentation for the "importdata" function.
Additionally, if you are working with tables, you might consider using the "readtable" method. It could be beneficial to explore and learn more about it to see if it suits your use cases. You can find more information about "readtable" on the documentation page linked below.
I hope these suggestions help you resolve the issue. If you have any further questions, please feel free to ask.
Best regards,
Gyan

Produkte


Version

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by