dynamic title in app.UIAxes won't work

12 vues (au cours des 30 derniers jours)
Raymond Gilbers
Raymond Gilbers le 2 Juin 2021
Commenté : Raymond Gilbers le 3 Juin 2021
Good evening,
Apearantly im doing something completely worng therefore the next question. I have a UIAxes on my canvas and want to make the title dynamic. So the name of the title will change according certain radioboxes I have. I created a function but when the function gets called and prepare the string then the title will be set and I get an error.
%This part happens in the plot function which was working until I tried to
%fix the title, in properties header is defined
app.strOpt = 'Cumulative';
app.strData = 'Cases';
header = app.PlotTitles();
title(app.UIAxes, header );
Than I have a function as below:
function Out = PlotTitles(app)
str = strcat({app.strData}, {' of COVID-19 '}, {app.strOpt});
disp(str)
select = app.CountryListBox.Value;
t = strcmp(select, 'Global');
if t == 0
Out = strcat({str}, {' in '},{app.CountryListBox.Value});
disp(Out)
else
Out = strcat({'Global '}, {str});
disp(Out)
end
end
I get an error that tells me that:
Error using matlab.graphics.primitive.Text/set
Error setting property 'String' of class 'Text':
I do no tunderstand what goes wrong, I used the disp() function to see what goes fine disp(str) works but disp(out) doesn't show anything on the command window.
Coul danybody tell what I do wrong, thanks in advance

Réponse acceptée

Cris LaPierre
Cris LaPierre le 2 Juin 2021
Modifié(e) : Cris LaPierre le 2 Juin 2021
Your function is working, but it is returning a 1x3 cell array. Title does not accept a cell array of cells.
When building your strings using strcat, only put the character vectors in curly braces. Here's a simplified example.
%This part happens in the plot function which was working until I tried to
%fix the title, in properties header is defined
app.strOpt = 'Cumulative';
app.strData = 'Cases';
header = PlotTitles(app);
{'Cases of COVID-19 Cumulative'} {'Cases of COVID-19 Cumulative in United States'}
title(header);
function Out = PlotTitles(app)
str = strcat(app.strData, {' of COVID-19 '}, app.strOpt);
disp(str)
app.CountryListBox.Value = 'United States';
Out = strcat(str, {' in '},app.CountryListBox.Value);
disp(Out)
end
  1 commentaire
Raymond Gilbers
Raymond Gilbers le 3 Juin 2021
Thank you very much I really did not see this error great lesson for me .

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Environment and Settings dans Help Center et File Exchange

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by