필터 지우기
필터 지우기

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

조회 수: 4 (최근 30일)
Naoki Ishibashi
Naoki Ishibashi 2016년 9월 27일
댓글: michio 2016년 9월 27일
複数のテキストデータ、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
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
Teja Muppirala 2016년 9월 27일
2番目以降のscatterplotに、最初に作成されたscatterplotのfigureハンドルを与えれば、figureが再利用できます。
たとえば:
h = scatterplot(randn(100,2));
hold on;
scatterplot(randn(100,2),[],[],'r.',h);

추가 답변 (1개)

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

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Scatter Plots에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by