필터 지우기
필터 지우기

plot while using for loops

조회 수: 1 (최근 30일)
john
john 2011년 2월 27일
Hello, I am a beginner in using matlab. I present my image as a 4x4 array and firstly I rescale my image with different intervals, starting from 0 and ending to 20 by step 10.Then, I am trying to get the ROI which is located in the central of my image.After this, I calculate the mean value and the std deviation of this ROI. Finally, I am trying to plot of (interval,mean_value) and (interval,std deviation) for every step of my increased interval. Well, the results of median value and std deviation look correct but my problem is how to plot my results. Does anybody know how to create these plots? (I put my code after this message)
Thanks in advance.
A=[ 30,31,12, 9,
17,12,25,10,
12, 8,17, 9,
31,12,26,22];
A=double(A);
x=size(A,1);y=size(A,2);
for interval=0:10:20
max_A=max(max(A));min_A=min(min(A));
for i=1:x
for j=1:y
val=A(i,j);
tone_ival=[(val-min_A)*(interval/(max_A-min_A))];
B(i,j)=tone_ival;
end;
end;
disp(round(B));
for i=1:1:2
for j=1:1:2
ROI(i,j)=B(((x/2)+(i-1)),((y/2)+(j-1)));
end;
end;
disp(round(ROI));
%%%calculate mean value
sum=0;
for i=1:1:2
for j=1:1:2
sum = sum + ROI(i,j);
end;
end;
mean_value = sum / 4;
disp(mean_value);
%%%calculate std deviation
sum_dev = 0;
for i=1:1:2
for j=1:1:2
sum_dev = sum_dev + ((ROI(i,j)- mean_value)^2);
end;
end;
std_dev = ((sum_dev/(4-1))^(1/2));
disp(std_dev);
end;

답변 (1개)

Paulo Silva
Paulo Silva 2011년 2월 27일
Do you want to plot all in the same axes?
clc;clf;hold all
mean_v=[];
std_d=[];
inter=[];
A=[ 30,31,12, 9
17,12,25,10
12, 8,17, 9
31,12,26,22];
A=double(A);
x=size(A,1);y=size(A,2);
for interval=0:10:20
max_A=max(max(A));min_A=min(min(A));
for i=1:x
for j=1:y
val=A(i,j);
tone_ival=[(val-min_A)*(interval/(max_A-min_A))];
B(i,j)=tone_ival;
end;
end;
disp(round(B));
for i=1:1:2
for j=1:1:2
ROI(i,j)=B(((x/2)+(i-1)),((y/2)+(j-1)));
end;
end;
disp(round(ROI));
%%%calculate mean value
sum=0;
for i=1:1:2
for j=1:1:2
sum = sum + ROI(i,j);
end;
end;
mean_value = sum / 4;
disp(mean_value);
%%%calculate std deviation
sum_dev = 0;
for i=1:1:2
for j=1:1:2
sum_dev = sum_dev + ((ROI(i,j)- mean_value)^2);
end;
end;
std_dev = ((sum_dev/(4-1))^(1/2));
disp(std_dev);
inter=[inter interval];
mean_v=[mean_v mean_value];
std_d=[std_d std_dev];
end
plot(inter,mean_v)
plot(inter,std_d,'r')
xlabel('intervals')
legend('mean values','std dev values',2)
  댓글 수: 2
john
john 2011년 2월 27일
It was that I was looking for...Thanks
bym
bym 2011년 2월 27일
you should "accept" Paulo's answer in addition to commenting

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

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by