フィルターのクリア

Cell array indexing in loop for subplot titles

2 ビュー (過去 30 日間)
Jason
Jason 2019 年 10 月 22 日
編集済み: Stephen23 2019 年 10 月 22 日
Hello, I can't see where my mistake is.
I have data (from a uitable) in whcih columns 2-6 are values I want to plot on 5 different subplots:
title={'# objects','centroid mean','centroid mode','FM','Q99'}
n=size(data,1) %number of rows in my data table
X=linspace(1,n, n)
for i=2:6
Y=data(:,i)
if isa(Y,'cell') %if data is a cell array, then convert to ordinary data type.
Y=cell2mat(Y);
end
subplot(2,3,i-1)
plot(X,Y,'r*--')
grid
set(gca,'fontsize',8)
tl=title{i-1}
class(tl)
title(tl,'color','r')
end
Im getting an error message (in the line title(tl,'color','r')) :
'Index in position 1 exceeds array bounds (must not exceed 1).'

採用された回答

Stephen23
Stephen23 2019 年 10 月 22 日
編集済み: Stephen23 2019 年 10 月 22 日
You defined a variable named title:
title={'# objects','centroid mean','centroid mode','FM','Q99'}
which shadows the title function (making the title function unusable). You then use indexing into your variable (which you probably think is calling the title function, but in reality is subscript indexing, because you defined that title variable):
title(tl,'color','r')
Do NOT use title as a variable name! (or save or cell or length or ...)
Change that variable name to something else, clear your workspace, and try again.
  1 件のコメント
Jason
Jason 2019 年 10 月 22 日
AH yes, perfect thankyou!
Jason

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

その他の回答 (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