dot indexing not supported for this type of variable” error

조회 수: 7 (최근 30일)
Ceren
Ceren 2024년 12월 5일
답변: Walter Roberson 2024년 12월 5일
% Perform prediction
pred =model.predictFcn(audioTable);
For this code
There is a "Dot indexing is not supported for variables of this type error"
function audioTable = extractFeatures(~, filePath)
% Ensure filePath is a valid string (for debugging purposes)
if ~ischar(filePath) && ~isstring(filePath)
error('Invalid file path');
end
% Reading audio file
[y, ~] = audioread(filePath);
% Processes the signal to suitable format
y1=abs(spectrogram(y,kaiser(2048,128),120,16,1E3,'yaxis'));
y1=y1(:);
audioTable=[];
t=0;
if length(y1)>=3087
y1=y1(1:3087);
else
t=1;
end
if t==0
audioTable=[audioTable y1];
end
end
and This is the code that I wrote. How can I fix this error?
  댓글 수: 2
dpb
dpb 2024년 12월 5일
What does
whos model
return?
And what generated it? It is undefined in the above code.
Image Analyst
Image Analyst 2024년 12월 5일
편집: Image Analyst 2024년 12월 5일
Which version of predict() are you using? There are lots of them. Are you sure it's not supposed to be like this:
pred = predictFcn(model, audioTable);
Check the arguments that are expected for the specific version of predict you're using. It's overloaded so the version of predict that gets used depends on what arguments you feed it. What does this show in the command window:
whos model
which -all model
which -all predict

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

답변 (2개)

Subhajyoti
Subhajyoti 2024년 12월 5일
Hi @Ceren,
The function 'audioTable = extractFeatures(~, filePath)' is returning a vector (nx1 double) or a null element '[]'.
In MATLAB, dot indexing is typically used with structures, tables, or objects, where you access fields or properties using a "." (dot). However, when you try to use dot indexing on a vector, MATLAB throws the error because vectors do not have fields or properties that can be accessed with dot notation. You can use parentheses '( )' for indexing and manipulation of elements of a double array.
Thus, for resolving the error, you need to ensure that appropriate operations are performed in the 'predictFcn' method to get results from the input 'audioTable'.
Refer to the following MathWorks Documentation to know more about 'Array Indexing' in MATLAB:

Walter Roberson
Walter Roberson 2024년 12월 5일
When you use predictFcn, the input data needs to be in the same format that you trained on.
If you trained on a table() object, then you need to pass predictFcn() a table() object. But you are passing numeric data instead.

카테고리

Help CenterFile Exchange에서 AI for Signals에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by