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 CenterFile Exchange에서 Environment and Settings에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by