Update multiple plots in loop and plot them in correct axes

13 Ansichten (letzte 30 Tage)
Hi all,
I'm trying to implement a GUI in MatlabR2019b that displays the data sent from my embedded system. The main problem I'm facing is that my data gets plotted in the wrong window (I'm opening the GUI from another GUI window).
I'd like my GUI to be dynamic in the sense that I can adjust the amount of channels I want to plot. Thus my idea was to do something like this:
data = zeros(numberOfSamples,numberOfChannels);
time = linspace(0,recordingTime,numberOfSamples);
t = tiledlayout(app.Panel,numberOfChannels,1);
for ch=1:numberOfChannels
nexttile(t);
plotList{ch} = plot(time,data(:,ch));
end
for sample = 1:numberOfSamples
data(sample,:) = read(serialObj,numberOfChannels,'single');
for ch=1:numberOfChannels
set(plotList{ch},'YData', data(:,ch))
end
end
But the data does not get plotted in the tiles as I would like them to be. I've come to understand that the problem is based on Matlab deleting the plot objects when a new one is created (resulting in a empty GraphicsPlaceholder array). I have also tried to store the handles to the axes and/or addding them to the plot instead of replacing them, so I can later on retrieve the plot handles from the axes:
axesList{ch} = nexttile(t);
axesList{ch}.NextPlot = 'add'
.
.
.
plt = get(axesList{ch}, 'children') % or alternatively access the axes with app.Panel.Children.Children(ch)
set(plt,'YData', data(:,ch))
But also this did not draw the the plots correctly. However it seems that the axes handles can be saved like this.
As on of my main concerns is fast visual updatess of the GUI, my next hope was using animatedLines
axesList{ch} = nexttile(t);
linesList{ch} = animatedline;
.
.
.
axes(axesList{ch});
addpoints(linesList{ch},time(sample),data(sample,ch))
This does draw the plots in the old window as well. But Matlab seems to discourage axes() in a loop for performance reasons anyways.
Does anybody know a way of how to do this so it plots in the correct axes?
  3 Kommentare
Jan Zbinden
Jan Zbinden am 21 Feb. 2020
The problem is more that the graphs get plotted into the wrong axes, and not that they need to be hidden. But thanks for the suggestion.

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Jan Zbinden
Jan Zbinden am 24 Feb. 2020
Found a solution (link) that fixed my problem and figured I'd share it.
In case of the animatedline example, assigning the parent axes fixes the plotting problem:
for ch=1:numberOfChannels
axesList{ch} = nexttile(t);
linesList{ch} = animatedline('Parent', axesList{ch});
end

Weitere Antworten (0)

Kategorien

Mehr zu 2-D and 3-D Plots finden Sie in Help Center und File Exchange

Produkte


Version

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by