Effacer les filtres
Effacer les filtres

複数のテキストデータから一つの散布図の作り方

4 vues (au cours des 30 derniers jours)
Naoki Ishibashi
Naoki Ishibashi le 27 Sep 2016
Commenté : michio le 27 Sep 2016
複数のテキストデータ、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 commentaire
Teja Muppirala
Teja Muppirala le 27 Sep 2016
ちなみに、 その '0' をつけるかつけないかの処理は sprintfを利用すれば、楽です。(わざわざif/elseを使わなくてもいい)
for i = 1:12
for j = 1:31
filename = sprintf('TA2004%02d%02d.txt',i,j)
end
end

Connectez-vous pour commenter.

Réponse acceptée

Teja Muppirala
Teja Muppirala le 27 Sep 2016
2番目以降のscatterplotに、最初に作成されたscatterplotのfigureハンドルを与えれば、figureが再利用できます。
たとえば:
h = scatterplot(randn(100,2));
hold on;
scatterplot(randn(100,2),[],[],'r.',h);

Plus de réponses (1)

michio
michio le 27 Sep 2016
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 commentaires
Teja Muppirala
Teja Muppirala le 27 Sep 2016
if i==1
h = scatterplot(x);
...
Should be if i==1 && j == 1
michio
michio le 27 Sep 2016
Ah, you are correct. Thanks for pointing that out :)

Connectez-vous pour commenter.

Catégories

En savoir plus sur Scatter Plots dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by