how to take the exact coordinates of non zero values of a matrix

조회 수: 1 (최근 30일)
Mary Kodogianni
Mary Kodogianni 2011년 4월 19일
I'm trying to take the non zero values of gaussian spots that i generate random. I round my table but I don't take the exact coordinates I think. Could anybody help me with this? Here is my code in which I save the nonzero coordinates.
function[n_min,n_max,max_val,spot,x1,y1,n_z]=generate_spot_7(i,sigma_x,sigma_y,x0,y0,n,min_n,max_n)
new_min=min_n/255;
new_max=max_n/255;
n_min=new_min+(new_max-new_min).*rand;
n_max=(n_min)+(new_max-n_min).*rand;
Z=0;
t=0;
theta=0+i*pi/500;;%allazoume tixaia tis esties ton elipseon
a = cos(theta)^2/2/sigma_x^2 + sin(theta)^2/2/sigma_y^2;
%b=0;
b = -sin(2*theta)/4/sigma_x^2 + sin(2*theta)/4/sigma_y^2 ;
c = sin(theta)^2/2/sigma_x^2 + cos(theta)^2/2/sigma_y^2;
%%%c=1;
[X, Y] = meshgrid(-(n+2*4):.13:(n+2*4), -(n+2*4):.13:(n+2*4));
t=exp( - (a*(X-x0).^2 + 2*b*(X-x0).*(Y-y0) + c*(Y-y0).^2));
MAX=max(t);
o=round(t*100000)/100000;%epeidi einai double kano strogilopoiisi g na paro
n_z=find(o~=(0));
[x1,y1] = ind2sub(size(o),find(o~=0))
s=[n,n];
%[x1,y1] = ind2sub(s,n_z)
max_val=max(MAX);
spot=t;
I observe that when I add the generated spots and i'm going to zero the values of some spots, I zero more pixels than those I want to zero.

답변 (1개)

Sean de Wolski
Sean de Wolski 2011년 4월 19일
n_z = find(~o);
[x1,y1] = ind2sub(size(o),n_z)
  댓글 수: 2
Matt Fig
Matt Fig 2011년 4월 19일
Or simply
[x1,y1] = find(~o);
Mary Kodogianni
Mary Kodogianni 2011년 4월 19일
This doesn't seem to work with my images very well.I make images with lots of spots but when I just go to zero the value with coordinates of a particular spot it zeros all of the spots.
I tryed this code instead and It seems to work better but not perfect
[x1,y1] = ind2sub(size(o),find(o));

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

카테고리

Help CenterFile Exchange에서 Mathematics and Optimization에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by