Stackedplot error when changing position and plotting again

Hello together,
I get an error with stackedplot, when changing position (which works always the first time) and plotting then again, adding new variables. Without the position change, there is no error and I can plot on.
That's the code I use. Without the "Position" line it works fine all the time. With the position change I get an error (below code).
app.Logs(app.Log).Stack{1} = stackedplot(app.Logs(app.Log).Table, app.Logs(app.Log).ToPlot,'Parent',app.StackedTab);
for e=1:+1:height(app.Logs(app.Log).Stack{1}.DisplayLabels)
emptyLabels(e,1) = ""; % Create empty string for label
end
if app.Logs(app.Log).Plots > 0
app.Logs(app.Log).Stack{1}.DisplayLabels = emptyLabels; % "Delete labels"
app.Logs(app.Log).Stack{1}.Position = [0.05,0.05,0.90,0.90]; % Get rid of the broad margin
end
Thats the error:
Error using stackedplot (line 100)
Brace indexing is not supported for variables of this type.
Error in LogReader/DataButtonPress (line 141)
app.Logs(app.Log).Stack{1} =
stackedplot(app.Logs(app.Log).Table,
app.Logs(app.Log).ToPlot,'Parent',app.StackedTab);
Error in LogReader>@(varargin)app.DataButtonPress(varargin{:}) (line 336)
app.Logs(app.Log).Variables{2, i}.ValueChangedFcn =
@app.DataButtonPress; %Callback function
Error using matlab.ui.control.internal.controller.ComponentController/executeUserCallback (line 429)
Error while evaluating StateButton PrivateValueChangedFcn.
What am I not understanding? ^^
Thanks in advance!
Christof

4 commentaires

Is app.Logs(app.Log).Stack initialized before the first line? Is app.Logs(app.Log).Stack overwritten somewhere else in your code?
Does the ValueChangedFcn plot a new stackedplot every time it's evoked?
Thank you very much Adam!
Yes, the function plotted a new stackedplot. I thought, just overwriting it would be sufficient. But your hint helped! I just needed to delete the stackedplot before. And no, I didn't initialise the variable before. I still don't.
This works:
try
delete(app.Logs(app.Log).Stack{1});
catch
end
app.Logs(app.Log).Stack{1} = stackedplot(app.Logs(app.Log).Table, app.Logs(app.Log).ToPlot,'Parent',app.StackedTab);
for e=1:+1:height(app.Logs(app.Log).Stack{1}.DisplayLabels)
emptyLabels(e,1) = "";
end
if app.Logs(app.Log).Plots > 0
app.Logs(app.Log).Stack{1}.DisplayLabels = emptyLabels;
app.Logs(app.Log).Stack{1}.Position = [0.05,0.05,0.90,0.90];
end
If it works, all's well, but it surely looks like way overkill on nested referencing...
for e=1:+1:height(app.Logs(app.Log).Stack{1}.DisplayLabels)
emptyLabels(e,1) = "";
end
can be written as
emptyLabels=strings(size(app.Logs(app.Log).Stack{1}.DisplayLabels));
Christof
Christof le 9 Juin 2024
Modifié(e) : Christof le 9 Juin 2024
Hello dpb,
I'm not experienced in programming, especially in Matlab. My approach of this nested referencing is, to load one complete "Log" in one structure, so I can save and control all elements for the plot. When loading a log, over 500 elements are created dynamically - buttons, edit fields, plots etc. The number of elements can vary from Log to log. That's the way, I saw as "reasonable" with my knowledge so far.
But at least this "nested referencing" is not important for my stackedplot, because I create it each time dynamically and don't need to save it's properties, when loading the next log.
Thanks for the empty labels :) Nice function to create "nothing".
Have a good day!

Connectez-vous pour commenter.

 Réponse acceptée

dpb
dpb le 7 Juin 2024
Modifié(e) : dpb le 7 Juin 2024
tP=readtable("patients.xls","TextType","string");
hSP=stackedplot(tP,["Height","Weight","Systolic","Diastolic"]);
figure
vars=["Height","Weight","Systolic","Diastolic"];
hSP=stackedplot(tP,vars,'DisplayLabels',strings(size(vars)),'Position',[0.05,0.10,0.90,0.90]);
Get rid of the nested indexing of variables with cells...it's trying to dereference a non-cell object with the curlies that is the syntax problem...don't do that!!!

3 commentaires

Christof
Christof le 7 Juin 2024
Modifié(e) : Christof le 7 Juin 2024
Thank you very much for your approach dpb. I tried it, but still didn't get the result wished. The stackedplot plotted just over the "old" one. I guess, my question wasn't specific enough ^^
We can't run your app, but the approach shown will work if you save the figure and axis handles and reference them correctly.
The problem in your code is owing to the {} trying to dereference objects but it's not possible in isolation to see just what you're trying to do.
With or without {} it didn't work properly. I had to delete the stackedplot first, as I wrote.
Now it still works with {}. I will remove them, as soon, as I am finished. At least the {} give me the possibility to look into the variables. Or I am understanding something wrong ^^

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Creating, Deleting, and Querying Graphics Objects dans Centre d'aide et File Exchange

Produits

Version

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by