Hey peeps,(adsbygoogle = window.adsbygoogle || []).push({});

I was bored the other day and wanted to paint something, so I started tweaking images in mathematica to make them eaiser to paint/draw and I came across de jong attractors and the following http://flam3.com/flame.pdf" [Broken].

Basically I immediately remembered I had forgotten most of my matlab but I got reasonably far until hitting a key roadblock, which I think I could have probably overcome with some janky coding but I really want to know the one line method for doing what I really wanted.

As I stated in the title, I basically want to the following as described in the paper:

("Information is lost every time we plot a point that has already been plotted. A more interesting image can be produced if we render a histogram of the chaotic process, that is, increment a counter at each pixel instead of merely plotting. These counters can be visualized by mapping them to shades of gray or by using a color-map that represents different densities (larger count values are more dense) with different colors. A linear mapping of counters to gray values results in Figure 3b.")

Once I had the bin values from said histogram, I could normalize them to highest bin amount and then take the log to give myself a log density map and hence cover a much larger dynamic range. The other things will probably require some more learning but right now this is where I'm stuck.

Heres the simplest way I think I can put forth my issue:

heres my example array where x is column 1 and y is column 2

example=[0 0;

3 3;

1 1;

3 1;

2 2;

2 2;

0 0];

obviously each pair is a data point generated in my code.

I want to get to here:

exfreq=

[ 0 0 2;

1 1 1

2 2 2

3 1 1

3 3 1 ]

Where the third column would be the number of times each 2D point in space got hit. Obviously the repeats in the first two columns would disappear and only unique values would be listed.

I was thinking unique() and accumarray() are probably going to be the answer here but I just don't know how to utilize them and the manual doesn't help. I've been getting incredibly frustrated that I can't seem to find any help what so ever for this type of problem. Simply running sort() on the 2D array puts it in a more useful form where all the x values are grouped but I can't formulate an elegant and quick way to get where I want to be.

Here is the code for two things I did:

dejong attractor:

-----------------------

close all

clear all

i=200000;

x=zeros(1,i);

y=zeros(1,i);

x(1)=3*rand()-1.5; %generates initial points for loop

y(1)=3*rand()-1.5;

A= 4*rand()-2; %generates random coefficients

B= 4*rand()-2;

C= 4*rand()-2;

D= 4*rand()-2;

for n=1:i

x(n+1) = sin(A.*(y(n)))-cos(B.*(x(n))); %eqns for de jong attractor

y(n+1) = sin(C.*(x(n)))-cos(D.*(y(n))); %

end

plot(x,y,'.','MarkerSize',1) %essentially makes a scatter plot that appears

% to be 3D due to gangsterness

q(:,1)=x;

q(:,2)=y;

qr=round(q*1000); % concatenates into one two column vector with integer

% values(perhaps there is a better way to do this histogram.

----------------------------------------

And here is the serpinksi gasket garb:

close all

clear all

clc

%This Program generates Sierpinski's Gasket

i=1000000; % number of iterations

x=zeros(1,i); % preallocates for speed

y=zeros(1,i); % preallocates for speed

x(1)=2*rand()-1; % these values generate a random number within

y(1)=2*rand()-1; % the bicubic square [-1,1]

for n=1:i

z=round(.0+2*rand()); % chaos game, selects btw 0 and 2, converts to integ.

if z == 0

x(n+1) = x(n)/2;

y(n+1) = y(n)/2;

elseif z == 1

x(n+1) = (x(n)+1)/2;

y(n+1) = y(n)/2;

else

x(n+1) = x(n)/2;

y(n+1) = (y(n)+1)/2;

end

end % end chaos game loop

x=x(1,50:end); % dumps first 50 iterations (recommended)

y=y(1,50:end);

plot(x,y,'.','MarkerSize',4) %plots all nice and pretty yo!

axis equal

q(:,1)=x;

q(:,2)=y;

qr=round(q*1000); % concatenates into one two column vector with integer values

example=[0 0;1 1;1 1;1 2;2 2];

Thanks guys,

this is my first post so please don't hesitate to suggest better formatting options for future questions.

Here's an output from the dejong attractor program as of nowhttp://imgur.com/wszvl" [Broken]

**Physics Forums | Science Articles, Homework Help, Discussion**

Join Physics Forums Today!

The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

# Counting Occurrences in a 2D Array with MATLAB

**Physics Forums | Science Articles, Homework Help, Discussion**