Error using hilbert transform: "Subscript indices must either be real positive integers or logicals."

Hello,
I have some troubles using hilbert transform for the enclosed vector in a guide.
The used command is:
y=abs(hilbert(A))/max(abs(hilbert(A)))
but Matlab sends the following error: "Subscript indices must either be real positive integers or logicals."
I can't understand why am i getting this error because i have already used this command in a former program successfully.
Any ideas please?

Risposte (1)

You accidentally assigned to a variable named "hilbert", which has the effect of overriding the meaning of hilbert() as a routine.

8 Commenti

Hi, Thank you for your reply. I got the same explanation elsewhere but i can't figure out where did i assigned to a variable named "hilbert". For me, i am just calling the function hilbert. Otherwise, how to fix it please?
@F Z: you have define some variable with the same name as an inbuilt function. This is a common error that beginners make. It might be hilbert, max or abs. but because you did not give us the whole error message we cannot tell which of these it is. You need to read the error message and check your code.
Please check that you have the Signal Processing Toolkit installed; you can check using ver()
Please report the result of
which -all hilbert
If it shows up then please show the code for your function.
For starters, the ver command is checked and returned that the signal processing toolbox is installed (version 6.22 - R2014b)
2nd: the command which all-hilbert returns: built-in (C:\Program Files (x86)\MATLAB\R2014b\toolbox\matlab\ops\@char\all) % char method
Finally, please find the code below:
function Start_Callback(hilbert, eventdata, handles)
% hObject handle to Start (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
Essaidata=getappdata(0,'Essaidata');
Essai_Bscan=Essaidata.data(:,((size(Essaidata.data,2)-1)/2)+2:end);
Essai_TOF=Essaidata.data(:,1);
Essai_pas=0.120;
Essai_scan=[0:Essai_pas:(size(Essai_Bscan,2)-1)*Essai_pas]';
Essai_EchoD=zeros(size(Essai_Bscan,2),1);
for i=1:size(Essai_Bscan,2)
Essai_EchoD(i,1)=max(abs(Essai_Bscan(:,i)));
end
[Essai_Amax,idx_maxEssai]=max(Essai_EchoD(:,1));
y=abs(hilbert((Essai_Bscan(:,idx_maxEssai))))/max(abs(hilbert((Essai_Bscan(:,idx_maxEssai)))));
Read your function definition again:
function Start_Callback(hilbert,...)
Do you see that you have defined a variable here with the name hilbert? When you use the name of an inbuilt function or variable it shadows the inbuilt function/variable, so the inbuilt one cannot be used. When you then try to use the function hilbert, it can only find the variable that you defined in your function definition, which is clearly a variable and thus clearly the code
hilbert(A)
is indexing a variable using A, and the values of A are somehow not suitable for indexing.
Solution: NEVER name your variable with the same name as an inbuilt function, e.g. size, length, i, j, cat, date, hilbert, etc. Before you use a variable name, use whose to check if it is already defined.
Thank you
Solution: NEVER name your variable with the same name as an inbuilt function. I'll never!!
We see this all the time. If it had been a case where the toolbox was not installed then the message would be about unknown variable or function.

Accedi per commentare.

Richiesto:

F Z
il 2 Ott 2015

Modificato:

il 3 Ott 2015

Community Treasure Hunt

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

Start Hunting!

Translated by