필터 지우기
필터 지우기

Plotting multiple histograms on same plot

조회 수: 2 (최근 30일)
Vinita
Vinita 2012년 4월 8일
Hi there. My problem is this I have a directory which has 3000 'dna.out' files. And this is how Im loading them all in matlab :
files = dir('*.out');
for i = 1 : length(files)
eval(['load ' files(i).name ]);
hist(files(i).name, 300);
hold on;
end
But I need to plot all these 3000 files in a single figure.How can I use the undermentioned code in a loop to plot all the loaded files.
[n,r]=hist(dna23,300);
plot(r,n,'r-');grid on;
hold on
Im currently doing it manually and i have 5 more folders having thousands of files. Please help

답변 (2개)

rob
rob 2012년 4월 8일
  댓글 수: 1
Vinita
Vinita 2012년 4월 8일
thanx rob, but how do i generate dataset from a directory which could be fed into histnorm.

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


Image Analyst
Image Analyst 2012년 4월 8일
You don't want to do a histogram of your filename (a character array). You want a histogram of the contents of the filename, right?
Don't use eval. Do it this way:
for k = 1 : length(files)
baseFileName = files(k).name;
if exist(baseFileName , 'file')
storedVariables = load(baseFileName);
dna23= storedVariables.dna23;
[counts binValues] = hist(dna23(:), 300);
if k == 1
allCounts = counts;
else
allCounts = allCounts + counts;
end
end
end
bar(allCounts);
Of course, don't forget to check that counts is the same size every time, to use fullfile(), try/catch, comments, and all the other things that go into making a robust and maintainable program.

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by