필터 지우기
필터 지우기

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

조회 수: 21 (최근 30일)
Dhaval
Dhaval 2023년 10월 9일
답변: Gyan Vaibhav 2023년 10월 18일
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
Rik
Rik 2023년 10월 9일
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 2023년 10월 9일
편집: Dyuman Joshi 2023년 10월 9일
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.

댓글을 달려면 로그인하십시오.

답변 (1개)

Gyan Vaibhav
Gyan Vaibhav 2023년 10월 18일
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

카테고리

Help CenterFile Exchange에서 Spreadsheets에 대해 자세히 알아보기

태그

제품


릴리스

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by