From: Philip on
So first, I am a very inexperienced programmer who often fails to see the best route for writing programs.

Right now, I have a logical matrix with either 1 surrounded by 0 or vice versa. I next calculate a fitness value for each location based on input rules for the 1 and 0s. Now, I need to compare each locations fitness values with its neighbors (using circshift) to see if the 1 will take over the 0 or the 0 will take over the 1. ie, if you have a neighbor of the opposite type, the one with the higher fitness takes over the lower.

Now, I must use circshift here and the way I am trying to do it is using a for loop and a nested for loop. The first for loop does circshift and the second does circshift one step ahead of the first. I then create a logical matrix p and assign true or false based on which one is larger for each step. This does not seem to work however.

note: this is for an assignment so any full, complete answer would be unethical. I am looking for any tips or hints.
From: ImageAnalyst on
I don't understand your algorithm. Personally I'd probably use
nlfilter() for that, or you can use blockproc() if you aren't
fortunate enough to have the Image Processing Toolbox.
From: Philip on
Thanks for the response. I was a little afraid I wasn't too clear.

I was actually able to make it through that part but now I am having some trouble with plotting.

so I am trying to do pcolor of a nxn matrix. for some reason, however, I get this error:

??? Error using ==> surface
Value must be numeric

Error in ==> pcolor at 71
hh = surface(zeros(size(x)),x,'parent',cax);




in that instance, I ran pcolor(x) where x was a 10x10 matrix of 1 and 0.

Thanks,
Phil
From: Steven Lord on

"Philip " <philipbrudnicki(a)jhu.edu> wrote in message
news:hpbrh0$2tr$1(a)fred.mathworks.com...
> Thanks for the response. I was a little afraid I wasn't too clear.
>
> I was actually able to make it through that part but now I am having some
> trouble with plotting.
> so I am trying to do pcolor of a nxn matrix. for some reason, however, I
> get this error:
>
> ??? Error using ==> surface
> Value must be numeric
>
> Error in ==> pcolor at 71
> hh = surface(zeros(size(x)),x,'parent',cax);
>
>
>
>
> in that instance, I ran pcolor(x) where x was a 10x10 matrix of 1 and 0.

From your description, I suspect that x is a logical array -- you can
confirm this by looking at WHOS, using CLASS on x, or using ISLOGICAL on x.
If so, the error message is correct -- the value must be numeric, and the
following returns false:

isnumeric(logical([0 1]))

Convert your logical array into a double array using DOUBLE and pass the
double version into PCOLOR.

--
Steve Lord
slord(a)mathworks.com
comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ


From: Philip on
"Steven Lord" <slord(a)mathworks.com> wrote in message <hpcoij$667$1(a)fred.mathworks.com>...
>
> "Philip " <philipbrudnicki(a)jhu.edu> wrote in message
> news:hpbrh0$2tr$1(a)fred.mathworks.com...
> > Thanks for the response. I was a little afraid I wasn't too clear.
> >
> > I was actually able to make it through that part but now I am having some
> > trouble with plotting.
> > so I am trying to do pcolor of a nxn matrix. for some reason, however, I
> > get this error:
> >
> > ??? Error using ==> surface
> > Value must be numeric
> >
> > Error in ==> pcolor at 71
> > hh = surface(zeros(size(x)),x,'parent',cax);
> >
> >
> >
> >
> > in that instance, I ran pcolor(x) where x was a 10x10 matrix of 1 and 0.
>
> From your description, I suspect that x is a logical array -- you can
> confirm this by looking at WHOS, using CLASS on x, or using ISLOGICAL on x.
> If so, the error message is correct -- the value must be numeric, and the
> following returns false:
>
> isnumeric(logical([0 1]))
>
> Convert your logical array into a double array using DOUBLE and pass the
> double version into PCOLOR.
>
> --
> Steve Lord
> slord(a)mathworks.com
> comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ
>

Thanks Steve. The problem is, that that error for x is in the matlabs native pcolor mfile that is run when I excecute pfile. My input into pcolor is a 1,0 array however.

So, executing double on each output solves the error, yet my plot is still wrong. I will have to look into this after class. Thanks!

-Phil