複数のテキストデータから一つの散布図の作り方
10 ビュー (過去 30 日間)
表示 古いコメント
複数のテキストデータ、TA20040101.txt から TA20041231.txt, を読み込みその値を一つの散布図にプロットしたいのですが以下の自分のプログラムだと1テキストファイルに一つの散布図が作られてしまいます。hold onが問題なんだと思うのですがいい考えがないのでアドバイスいただけると嬉しいです。
for i = 1:12
if i<10
monstr = ['0', num2str(i)];
else
monstr = num2str(i);
end
for j = 1:31
if j<10
daystr = ['0', num2str(j)];
else
daystr = num2str(j);
end
filename = ['TA2004',monstr,daystr,'.txt'];
x = load(filename);
scatterplot(x)
hold on
end
end
よろしくお願いします。
1 件のコメント
Teja Muppirala
2016 年 9 月 27 日
ちなみに、 その '0' をつけるかつけないかの処理は sprintfを利用すれば、楽です。(わざわざif/elseを使わなくてもいい)
for i = 1:12
for j = 1:31
filename = sprintf('TA2004%02d%02d.txt',i,j)
end
end
採用された回答
Teja Muppirala
2016 年 9 月 27 日
2番目以降のscatterplotに、最初に作成されたscatterplotのfigureハンドルを与えれば、figureが再利用できます。
たとえば:
h = scatterplot(randn(100,2));
hold on;
scatterplot(randn(100,2),[],[],'r.',h);
0 件のコメント
その他の回答 (1 件)
michio
2016 年 9 月 27 日
Communication System Toolboxの関数 scatterplot は実行毎に新しいFigureが作成されます。散布図を新規のFigureではなく、既存のFigureに追加する場合には、
scatterplot(x,n,offset,plotstring,h)
Figureハンドル h を引数に与える構文をhold onと共に使用します。
for i = 1:12
if i<10
monstr = ['0', num2str(i)];
else
monstr = num2str(i);
end
for j = 1:31
if j<10
daystr = ['0', num2str(j)];
else
daystr = num2str(j);
end
filename = ['TA2004',monstr,daystr,'.txt'];
x = load(filename);
if i==1
h = scatterplot(x);
hold on
else
scatterplot(rand(100,1),[],[],[],h);
end
end
end
またはMATLABの scatter 関数を代わりに使用してください。
2 件のコメント
参考
カテゴリ
Find more on Scatter Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!