problem with cellular automata code?

2 views (last 30 days)
sara
sara on 21 Oct 2014
Commented: Geoff Hayes on 23 Feb 2016
i found this code here, and i try to initialize it with [1 0 1 1 0 1 1] but it didn't work.
the code is long to paste it here. and how to locate the image?

Accepted Answer

Geoff Hayes
Geoff Hayes on 21 Oct 2014
Sara - how did you try to execute the code? Based on the given link, the function requires a rule (so this is an integer from 1 to 255), an optional initial state, and an optional number of rows (iterations for the cellular automata). What is your [1 0 1 1 0 1 1] - a rule or an initial state?
For example, the command
wolfram(45)
creates an interesting image, as does some of the other examples included in the comments (from the rich vector).
If your vector is an initial state, then you would specify the rule (1-255) and supply the state vector
wolfram(45, [1 0 1 1 0 1 1], 50);
Note that since your initial state is narrow (only 7 columns) then the number of rows should be kept small too else the image will be difficult to view.
  15 Comments
cathrin philo
cathrin philo on 22 Feb 2016
Edited: Geoff Hayes on 23 Feb 2016
thank you for your response.
if nargin < 300, nrows=221; end
if nargin < 300 %Use default initial state
ncols=228; A=zeros(nrows,ncols); A(1,ncols-1)=1;
else
[unused, ncols]=size(initialstate)
A=zeros(nrows, ncols); A(1,:)=initialstate;
end
rule=dec2bin(wolfrule,8);
where i have changed row=221;col=228. i don't know whether the output is for my input image or not? how can i procced with?
Geoff Hayes
Geoff Hayes on 23 Feb 2016
cathrin - you will need to update the wolfram function to return the output A as
function [A] = wolfram(wolfrule, initialstate, grows)
As for changing the nrows and ncols, why have you chosen 221 and 228? Are these the dimensions of your original image? Because I would think that you wouldn't have to modify these numbers at all. For example, suppose you wish to apply to the 40th row of your image which is a 256x512 image. Then you would call wolfram as
A = wolfram(150,myImg(40,:),256-40+1);

Sign in to comment.

More Answers (0)

Categories

Find more on Image Processing Toolbox 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!