Error : Dot indexing is not supported for variables of this type.
9 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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 comentarios
Rik
el 9 de Oct. de 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
el 9 de Oct. de 2023
Editada: Dyuman Joshi
el 9 de Oct. de 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.
Respuestas (1)
Gyan Vaibhav
el 18 de Oct. de 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
0 comentarios
Ver también
Categorías
Más información sobre Data Import and Analysis en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!