I think, I might have a problem with the 'hold' part and I get the 'error while evaluating button privatebuttonpushedfcn'

5 ビュー (過去 30 日間)
i have this in the code view for the app:
% Button pushed function: PlotButton
function PlotButtonPushed(app, event)
fnam = uigetfile ('*.dat','Escolha o ficheiro');
fid = fopen(fnam);
ecg = fscanf(fid,'%f');
fs = 200; %sampling rate
sze = length(ecg);
necg = ecg/max(ecg); % normalize the maximum value to unity
time = (1:sze)/fs;
[mins, maxs] = picos (necg);
figure;
plot(app.UIAxes, time, necg, 'b');
hold on;
plot (app.UIAxes, time(maxs), necg(maxs), 'red*');
plot (app.UIAxes, time(mins), necg(mins), 'ko'); hold off;
axis tight;
ylabel(app.UIAxes, 'ECG');
xlabel(app.UIAxes, 'Time in seconds');
But when i press run, and then the plot button, choose a file, all i get in the Axes window is the black dots that mark valleys in the signal plus, it opens a different window with a blank figure. I need to show the signal, the valleys marked with a dot and the peaks marked with a star in the app.UIAxes and i dont want to open the other window with the blank figure.
Here is the code for "picos" function:
function [mins, maxs] = picos (sinal)
mins = [];
maxs = [];
t = 1:length (sinal);
for i = 2:length(sinal)-1
if sinal(i-1) > sinal(i) && sinal(i) < sinal(i+1)
mins = [mins i]; %faz acrescentar o valor de i ao array mins
end
if sinal(i-1) < sinal(i) && sinal(i) > sinal(i+1)
maxs = [maxs i]; %faz acrescentar o valor de i ao array maxs
end
end
% plot (t, sinal, 'm-'); hold on;
% plot (t(maxs), sinal(maxs), 'b*');
% plot (t(mins), sinal(mins), 'go'); hold off;
% title ('Deteção picos'); xlabel ('Tempo (s)'); ylabel ('Sinal (t)');
end
Thank you!

採用された回答

Voss
Voss 2024 年 10 月 2 日

You need to tell hold() and axis() to operate on your app's axes:

...
hold(app.UIAxes,'on')
...
hold(app.UIAxes,'off')
...
axis(app.UIAxes,'tight')
...

And remove the "figure;" call if you don't want a blank figure to pop up.

その他の回答 (1 件)

Steven Lord
Steven Lord 2024 年 10 月 2 日
Don't call figure if you don't want to create a new figure.

カテゴリ

Help Center および File ExchangeApp Building についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by