MATLAB Answers

Appending different size arrays each itteration in app desinger

1 view (last 30 days)
I have an program which gets data from an oscilloscope and finds peaks in the signal, these peaks are stored in an private property called HoogtePulsen. And in one of the callbacks i want to put these peaks in an histogram.
function TimerFcn_Callback2(app,~,~)
%TimerFcn_Callback Timer callback function which executes periodically
% When LivePlotTimer is running this function does periodic waveform live plot updates
y = app.HoogtePulsen.Value * 100;
histogram(app.UIAxes_2,y,100,"BinLimits",463:464);
drawnow
end
This works fine, but i want to append the y value in an array every itteration of this callback. So i get an array of every peak found in all the measured signals of the oscilloscope. What is the easiest way to accomplish this in app desinger?

  0 Comments

Sign in to comment.

Accepted Answer

Tim Koopman
Tim Koopman on 6 Jul 2020
You could perhaps initialize a new property as an empty array and then append to this array with every iteration:
properties (Access = public)
yourArray = [];
end
This section of code should be somewhere in the beginning of your code, before the callbacks that handle component events.
You then append to this array in your TimerFcn_Callback2 callback:
app.yourArray(end+1,1) = y;

  3 Comments

remco wouters
remco wouters on 7 Jul 2020
properties (Access = public)
AllePieken = []; % Description
end
function TimerFcn_Callback2(app,~,~)
%TimerFcn_Callback Timer callback function which executes periodically
% When LivePlotTimer is running this function does periodic waveform live plot updates
y = app.HoogtePulsen.Value * 100;
app.AllePieken(end+1,1) = y;
data = app.AllePieken.Value;
histogram(app.UIAxes_2,data,100,"BinLimits",463:464);
drawnow
end
I now use this but it still doesn't work. Do you maybe know why?
Tim Koopman
Tim Koopman on 7 Jul 2020
Not totally sure without seeign the error message. My best guess is it is because app.AllePieken does not have a Value property.
Try using
data = app.AllePieken;
instead.
remco wouters
remco wouters on 10 Jul 2020
This worked perfect when i used cell arrays instead of normal arrays. Thank you for the help.

Sign in to comment.

More Answers (1)

Geoff Hayes
Geoff Hayes on 6 Jul 2020
remco - you could perhaps create a member variable for your App and then update that variable with the y on each call to the timer callback.

  1 Comment

remco wouters
remco wouters on 7 Jul 2020
What do you mean with a member variable? I set a private property.
properties (Access = private)
Allepieken % Description
end
And then i read the oscilloscope, and find the peaks in the signal.
function TimerFcn_Callback(app,~,~)
%TimerFcn_Callback Timer callback function which executes periodically
% When LivePlotTimer is running this function does periodic waveform live plot updates
y = readWaveform(app.Oscilloscope)';
acquisitionTime = app.Oscilloscope.AcquisitionTime;
waveFormLength = app.Oscilloscope.WaveformLength;
t = linspace(0, acquisitionTime, waveFormLength)';
pks = findpeaks(y,'MinPeakHeight',app.LLD.Value);
app.AantalPulsen.Value = numel(pks);
app.HoogtePulsen.Value = pks;
plot(app.UIAxes, t, y)
xlim(app.UIAxes, [t(1) t(end)])
drawnow
end
Then i want to plot these peaks and append new peaks found to already meassured peaks.
function TimerFcn_Callback2(app,~,~)
%TimerFcn_Callback Timer callback function which executes periodically
% When LivePlotTimer is running this function does periodic waveform live plot updates
y = app.HoogtePulsen.Value * 100;
histogram(app.UIAxes_2,y,100,"BinLimits",463:464);
drawnow
end
This works fine but, i want to append those y values in a array of all the meassured y values. I dont know how to append them to the Allepieken property. :(

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!