Borrar filtros
Borrar filtros

plot while using for loops

1 visualización (últimos 30 días)
john
john el 27 de Feb. de 2011
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;

Respuestas (1)

Paulo Silva
Paulo Silva el 27 de Feb. de 2011
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 comentarios
john
john el 27 de Feb. de 2011
It was that I was looking for...Thanks
bym
bym el 27 de Feb. de 2011
you should "accept" Paulo's answer in addition to commenting

Iniciar sesión para comentar.

Categorías

Más información sobre Polar Plots en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by