I want to repeat a section several times taking different values

조회 수: 5 (최근 30일)
aneps
aneps 2014년 4월 30일
답변: Star Strider 2014년 4월 30일
A section of my program is as follows:
Dat=[Data(:,1) Data(:,2)];
nbins=[100 100];
figure
hist3(Dat,nbins,'FaceAlpha',.85);%create 3D histogram plot
set(gcf,'renderer','opengl');
xlabel('X','color','w'); ylabel('Y','color','w');
title('3D histogram X Y','fontweight','bold');
surfHandle = get(gca, 'child');
set(surfHandle,'FaceColor','interp', 'CdataMode', 'auto');
caxis([0 100]);
n=hist3(Dat,nbins);
n1 = n';
n1(size(n,1) + 1, size(n,2) + 1) = 0;
xb = linspace(min(Dat(:,1)),max(Dat(:,1)),size(n,1)+1);
yb = linspace(min(Dat(:,2)),max(Dat(:,2)),size(n,1)+1);
figure
h = pcolor(xb,yb,n1);
caxis([0 20]);
xlabel('X');ylabel('Y');
title('2D histogram X Y','fontweight','bold');
I want to repeat this section several times (say n times). For example. For 'Data' in the program, I have several data 'TimePeriod1' 'TimePeriod2' 'TimePeriod3'....... 'TimePeriodn'. Means, in one run Data= TimePeriod1, the second run Data= TimePeriod2, so n so... For each run, it should output the figures separately. How can I repeat this section several times each time taking Data as TimePeriod1, TimePeriod2 etc..?

채택된 답변

Star Strider
Star Strider 2014년 4월 30일
I suggest putting it in a function m-file, pass the appropriate arguments to it, and return the appropriate output. Then, you simply call it as a function in a for loop, passing it ‘TimePeriod1’ etc. as arguments. If you want to save the figures the function creates, consider saving them with savefig.

추가 답변 (1개)

Sean de Wolski
Sean de Wolski 2014년 4월 30일

카테고리

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