dynamic title in app.UIAxes won't work
10 次查看(过去 30 天)
显示 更早的评论
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
0 个评论
采纳的回答
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);
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
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Introduction to Installation and Licensing 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!