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

1 view (last 30 days)
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.

Answers (1)

Sean de Wolski
Sean de Wolski on 19 Apr 2011
n_z = find(~o);
[x1,y1] = ind2sub(size(o),n_z)
  2 Comments
Mary Kodogianni
Mary Kodogianni on 19 Apr 2011
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));

Sign in to comment.

Categories

Find more on Mathematics and Optimization in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!