dynamic title in app.UIAxes won't work

12 ビュー (過去 30 日間)
Raymond Gilbers
Raymond Gilbers 2021 年 6 月 2 日
コメント済み: Raymond Gilbers 2021 年 6 月 3 日
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

採用された回答

Cris LaPierre
Cris LaPierre 2021 年 6 月 2 日
編集済み: Cris LaPierre 2021 年 6 月 2 日
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 件のコメント
Raymond Gilbers
Raymond Gilbers 2021 年 6 月 3 日
Thank you very much I really did not see this error great lesson for me .

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeEnvironment and Settings についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by