Unrecognized function or variable

13 visualizaciones (últimos 30 días)
toastgt
toastgt el 11 de Dic. de 2023
Editada: Image Analyst el 12 de Dic. de 2023
I'm having a problem where whenever I try to assign a function to a variable it says its an "Unrecognized function or variable" although its defined in my code. The code is below:
t = 1:1:2960;
t2= t/128;
t2 = t2';
%rc is raw data
%rcf is segmented data
fs = 128;
Lab5 = lowpass(realLab5.LEDC2,20,fs);
Lab5c= Lab5(116:2960);
m=1;
n=length(Lab5c);
for i = 2:n-1
if Lab5c(i)>Lab5c(i-1) && Lab5c(i)>=Lab5c(i+1) && Lab5c(i)> 488000
val(m) = Lab5c(i);
pos1(m) = i;
m = m+1;
end
end
ppg_peaks = m-1;
ppg_pos = pos1(m);
ppg_val = val;
The error is :
Unrecognized function or variable 'pos1'.
Error in Heart_Rate (line 22)
ppg_pos = pos1(m);
  1 comentario
Walter Roberson
Walter Roberson el 11 de Dic. de 2023
By the way, you might want to consider using findpeaks with the minimum peak prominence option

Iniciar sesión para comentar.

Respuestas (2)

Voss
Voss el 11 de Dic. de 2023
Editada: Voss el 11 de Dic. de 2023
if Lab5c(i)>Lab5c(i-1) && Lab5c(i)>=Lab5c(i+1) && Lab5c(i)> 488000
If that condition is never true then the block inside will never be executed
val(m) = Lab5c(i);
pos1(m) = i;
m = m+1;
So pos1 and val will be undefined after the loop ends and m will still be 1.

Image Analyst
Image Analyst el 12 de Dic. de 2023
Editada: Image Analyst el 12 de Dic. de 2023
Try this:
t = 1:1:2960;
t2= t/128;
t2 = t2';
%rc is raw data
%rcf is segmented data
fs = 128;
Lab5 = lowpass(realLab5.LEDC2,20,fs);
Lab5c= Lab5(116:2960);
m=1;
n=length(Lab5c);
% Assign nans to pos1:
pos1 = nan(1, n);
for i = 2:n-1
if Lab5c(i)>Lab5c(i-1) && Lab5c(i)>=Lab5c(i+1) && Lab5c(i)> 488000
val(m) = Lab5c(i);
pos1(m) = i;
m = m+1;
end
end
% Alert user if no element of pos1 ever got assigned.
if all(isnan(pos1))
warningMessage = sprintf('No element of pos1 ever got assigned!!!')
uiwait(warndlg(warningMessage));
end
ppg_peaks = m-1;
ppg_pos = pos1(m);
ppg_val = val;
Set a breakpoint on the pos1(m)=1 line and see if it ever gets there (it won't). See this link:

Community Treasure Hunt

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

Start Hunting!

Translated by