Unrecognized function or variable when reading an excel file.
이전 댓글 표시
This code is for monitoring BPM. Code works fine on another device without doing any changes. Can't figure why this error occures on this Matlab.
K = csvread("F:\DIP SEM 2\DIGITAL\Project B2\HeartBeatSample.csv") %path to the sample file
Time = K(1:45465,1);
Voltage= K(1:45465,2); %/amplitude
plot(Time,Voltage) % Plotting the virtual data that given
J = fir1(1000,1/1000*2,'high'); % Smoothing using high pass filter
Voltage_filter = filter(J,1,Voltage);
plot(Voltage_filter)
Findsq = Voltage_filter.^2;
plot(Findsq);
last = 0;
Point = 0;
pulse = zeros(length(Findsq),1);
for L = 1:length(Findsq)
if (Findsq(L) > 0.8)
if (Point == 0)
if (last > 0)
t = L - last;
p = 1000/t*60;
end
last = L;
end
Point = 100;
else
if (Point > 0)
Point = Point - 1;
end
end
pulse(L)=p;
end
plot(pulse); % plotting the pulse graph
%xlabel('Numbers Of Data');
ylabel('BPM')
title('BPM Graph');
DATA = findobj(gca,'Type','line')
y=get(DATA,'Ydata')
for L = 1:length(y)
if (y>0)
if (y<80)
disp("You're in Normal conditon")
elseif (y>90)
disp("You're in Stressed condition")
else
disp ("You're in Critical condition")
end
end
end
Error messege;
Unrecognized function or variable 'p'.
Error in Scenario2_groupB2 (line 35)
pulse(L)=p;
MATLAB Version 9.8 (R2020a)
Simulink Version 10.1 (R2020a)
Control System Toolbox Version 10.8 (R2020a)
DSP System Toolbox Version 9.10 (R2020a)
Data Acquisition Toolbox Version 4.1 (R2020a)
Signal Processing Toolbox Version 8.4 (R2020a)
Statistics and Machine Learning Toolbox Version 11.7 (R2020a)
Symbolic Math Toolbox Version 8.5 (R2020a)
댓글 수: 1
Salinda Nandasena Talapitiya Rallage
2020년 9월 21일
채택된 답변
추가 답변 (3개)
VBBV
2020년 9월 19일
편집: Walter Roberson
2020년 9월 21일
You have initialized last = 0; but you used a if condition as
if (last>0)
...
p = 100*t/60; %
end
Which Is not satisfied at beginning Later at the end of for loop you are assigning
pulse(L) = p; % p is not initialized / defined before anywhere except in the if condition.
Change if condition as
if (last>=0)
댓글 수: 5
Salinda Nandasena Talapitiya Rallage
2020년 9월 19일
편집: Salinda Nandasena Talapitiya Rallage
2020년 9월 19일
Image Analyst
2020년 9월 19일
It doesn't run for us. Why not? Because you keep forgetting to attach your data.
Salinda Nandasena Talapitiya Rallage
2020년 9월 19일
편집: Salinda Nandasena Talapitiya Rallage
2020년 9월 19일
VBBV
2020년 9월 19일
편집: Walter Roberson
2020년 9월 21일
Put the filepath as
K = csvread('...');
You have used a string " ..."
Image Analyst
2020년 9월 19일
Vashista - that does not matter. It will work either with single or double quotes.
Image Analyst
2020년 9월 19일
You need to initialize p because on the first time, you reference p but it never got inside the if block to be assigned:
for L = 1:length(Findsq)
p = 0;
if (Findsq(L) > 0.8)

댓글 수: 14
VBBV
2020년 9월 19일
This was my answer to him ... But he said that's not the problem . It works on other devices
Image Analyst
2020년 9월 19일
Sorry, you did say that. But either he's wrong or he's not telling us the whole story. SOMETHING changed if it's able to run on different computers, he just forgot to tell us what. Maybe it depends on the data or something.
Salinda Nandasena Talapitiya Rallage
2020년 9월 19일
Image Analyst
2020년 9월 19일
It's not a toolbox issue if it said that p was not defined. That's just a simple logic/programming error. I really doubt that that same program with same data would work on one computer but not another. Anyway, it works now. Does it work for you? Does it give you the expected and desired answer?
Salinda Nandasena Talapitiya Rallage
2020년 9월 19일
Image Analyst
2020년 9월 19일
Not sure what e is, but okay. Is there any problem, or even a question? If so, what?
Salinda Nandasena Talapitiya Rallage
2020년 9월 20일
Image Analyst
2020년 9월 20일
Did you use the debugger to step through your code and find out why it's not getting to the disp() commands? If not, why not?
Salinda Nandasena Talapitiya Rallage
2020년 9월 21일
Walter Roberson
2020년 9월 21일
if (y>0)
if (y<80)
disp("You're in Normal conditon")
Okay, to get to this disp(), y > 0 and y < 80
elseif (y>90)
disp("You're in Stressed condition")
And to get to this disp(), y > 0 and y >= 80 and y > 90, which can be simplified to y > 90.
else
disp ("You're in Critical condition")
And to get to this disp(), y > 0 and y >= 80 and y <= 90, which can be simplified to y >= 80 and y <= 90
... Are you sure that when you pass through "Normal" to "Stressed", that you are temporarily in Critical condition, but that clears up as your heart beats faster??
Salinda Nandasena Talapitiya Rallage
2020년 9월 21일
Salinda Nandasena Talapitiya Rallage
2020년 9월 21일
Walter Roberson
2020년 9월 21일
Then you want your elseif (y>90) to be elseif (y<=90)
Salinda Nandasena Talapitiya Rallage
2020년 9월 21일
Walter Roberson
2020년 9월 21일
When you have if expression then MATLAB considers the condition to be true only if all values of the expression are non-zero.
You are testing if y < 80 (for example) . y is a vector. Thus the test will only succeed if all y values are < 80. If for example all but one of them were less than 80 but the last one of them was 81, then it would not be the case that all of them were true (non-zero) and MATLAB would consider the condition to fail.
This also applies to your initial y > 0 test: if there is even one y value that is <= 0 then your entire outer if would be considered to fail and the inner test would not be done.
for L = 1:length(y)
As you are taking length(y) the implication is that you expect y to be a non-scalar at that point, probably a vector. You then loop with L taking on successive values from 1 to the number of entries in y.
Then inside that for L loop, you always do exactly the same thing for every different L value, and what you do does not depend upon the value of L. Every time, you are testing all of y in your statements.
Have you considered the possibility that inside your loop you should only be testing the "current" value of y -- the one indexed by y(L) ?
댓글 수: 4
Salinda Nandasena Talapitiya Rallage
2020년 9월 21일
Walter Roberson
2020년 9월 21일
for L = 1:length(y)
if (y(L)>0)
if (y(L)<80)
disp("You're in Normal conditon")
elseif (y(L)<=90)
disp("You're in Stressed condition")
else
disp ("You're in Critical condition")
end
end
end
However, you are just going to get a stream of those, one per point in your graph. You should consider displaying the time as part of the message. You should also consider only displaying the message when you change state.
Image Analyst
2020년 9월 21일
Perhaps
yPrior = rand(1); % Initialize
for L = 1 : length(y)
if y(L) > 0 && y(L) ~= yPrior
if y(L) < 80
disp("You're in Normal condition.")
elseif y(L) <= 90
disp("You're in Stressed condition.")
else
disp("You're in Critical condition.")
end
end
yPrior = y(L);
end
Salinda Nandasena Talapitiya Rallage
2020년 9월 21일
편집: Salinda Nandasena Talapitiya Rallage
2020년 9월 21일
카테고리
도움말 센터 및 File Exchange에서 Low-Level File I/O에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
