Unrecognized function or variable

조회 수: 13 (최근 30일)
toastgt
toastgt 2023년 12월 11일
편집: Image Analyst 2023년 12월 12일
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
Walter Roberson
Walter Roberson 2023년 12월 11일
By the way, you might want to consider using findpeaks with the minimum peak prominence option

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

답변 (2개)

Voss
Voss 2023년 12월 11일
편집: Voss 2023년 12월 11일
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 2023년 12월 12일
편집: Image Analyst 2023년 12월 12일
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:

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by