How do I name a graph using a string with probplot?

1 回表示 (過去 30 日間)
Janna Hinchliff
Janna Hinchliff 2019 年 2 月 18 日
回答済み: dpb 2019 年 2 月 18 日
I'm trying to change the title of a probplot graph to a string that is dependent on the parameters calculated in a loop. The code I'm using is
for i = 1:N
fig1 = figure;
plotprob = probplot('lognormal',censoredFailTime,censored,'noref'); % does a lognormal plot of percentage failed over time - parameters have been calculated previously
set(plotprob(1),'Color',[0.5 0 0.5]) % gives colour of graph
grid on
xlabel('Time (h)','FontSize',16)
ylabel('Proportion failed','FontSize',16)
titlestr = strcat('Number of VCSELs = ',num2str(size(data,2)),' Number of failures = ',num2str(NFail)) % calculates the parameters and makes string
title('titlestr') % I want this to show titlestr as the graph title
end
The gives me the error 'index exceeds array bounds' on the title line. titlestr is printed as I want it but it isn't converting to a graph title, what is going wrong?

採用された回答

dpb
dpb 2019 年 2 月 18 日
titlestr=strcat('Number of VCSELs = ',num2str(size(data,2)),' Number of failures = ',num2str(NFail))
title('titlestr') % I want this to show titlestr as the graph title
You don't show data so can't help debug that without more context.
But, the title() call simply passes the text string titlestr to the function, not the variable of that name--remove the quotes.
titlestr=sprintf('Number of VCSELs = %d. Number of failures = %d',size(data,2),NFail);
is just a little cleaner way to write/format the desired string; you'll have to uncover the root cause for the error or post more details on it...

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeTitle についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by