Unrecognized function or variable
13 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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);
Antworten (2)
Voss
am 11 Dez. 2023
Bearbeitet: Voss
am 11 Dez. 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.
0 Kommentare
Image Analyst
am 12 Dez. 2023
Bearbeitet: Image Analyst
am 12 Dez. 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:
0 Kommentare
Siehe auch
Kategorien
Mehr zu String finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!