problem with cellular automata code?
現在この質問をフォロー中です
- フォローしているコンテンツ フィードに更新が表示されます。
- コミュニケーション基本設定に応じて電子メールを受け取ることができます。
エラーが発生しました
ページに変更が加えられたため、アクションを完了できません。ページを再度読み込み、更新された状態を確認してください。
古いコメントを表示
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?
採用された回答
Geoff Hayes
2014 年 10 月 21 日
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 件のコメント
sara
2014 年 10 月 22 日
編集済み: Geoff Hayes
2016 年 2 月 10 日
i try this code and didn't run,
if nargin < 3, nrows=700; end
if nargin < 2 %Use default initial state
ncols=700; 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);
wolfram(45, [1 0 1 1 0 1 1], 50)
for i=1:8
ru(i)=str2num(rule(i))
my origion intial value is:
[ 1 1 0 1 0 0 0 0 1 0 0 1 0 0 0 1 1 0 1 1 1 0 1 1 0 1 0 0 0 1 0 0]
how and where to insert this vector? and i want to use rule 150 with this code, i try
rule=dec2bin(150,8);
and it didn't accept.
Geoff Hayes
2014 年 10 月 22 日
Sara - the function signature is
function wolfram(wolfrule, initialstate, brows)
The first input parameter, wolfrule, is the rule and is a number from 1-255. The second input parameter, initialstate, is the initial state of your cellular automata and is a vector (optional). The third input parameter, brows, is the number of rows/iterations for the automata (optional).
If you want to use rule 150, then you pass this value as the first input parameter. If you want to use your original initial state from above, then pass that as the second input parameter. The code will then do the necessary conversion of the rule from an integer to a binary string.
So try
initialState = [ 1 1 0 1 0 0 0 0 1 0 0 1 0 0 0 1 1 0 1 1 1 0 1 1 0 1 0 0 0 1 0 0];
rule = 150;
wolfram(rule,initialState,150);
I added the 150 for the number of rows/iterations because that seemed reasonable given the state vector size. You can change this to whatever you wish.
sara
2014 年 10 月 22 日
hi Geoff i try the code , it didn't run it gives this error:
??? Maximum recursion limit of 500 reached. Use set(0,'RecursionLimit',N) to change the limit. Be aware that exceeding your available stack space can crash MATLAB and/or your computer.
Error in ==> wolfram
Geoff Hayes
2014 年 10 月 22 日
Sara - are you running the three lines of code from the Command Window, or have you pasted it into the wolfram.m file? If the latter, then that is incorrect and would cause the recursive error from above. Just copy
initialState = [ 1 1 0 1 0 0 0 0 1 0 0 1 0 0 0 1 1 0 1 1 1 0 1 1 0 1 0 0 0 1 0 0];
rule = 150;
wolfram(rule,initialState,150);
and paste it into the Command Window (you may need to press enter/return to execute the code).
sara
2014 年 10 月 23 日
dear Geoff - i paste it in the command window and i run it, but it gave the same message. try it please and check it. but when i change the line rule=dec2bin(wolfrule,8); to rule=dec2bin(150,8);and the title (last line) to 150. it gave the picture . but i still can't provide my own intialstate.
Geoff Hayes
2014 年 10 月 23 日
Sara - you must have made some changes to the wolfram.m file which is causing it to fail. Delete your version of wolfram.m, download the original from the link that you provided, don't modify the code, and then run the above three lines in the Command Window.
I'm not sure what you mean by but when i change the line ... the title (last line) to 150 because it seems to imply that you have modified the function signature and so have removed the input parameter named wolfrule and either replaced it with something else or it has disappeared entirely.
The first line in the file wolfram.m is
function wolfram(wolfrule, initialstate, brows)
sara
2014 年 10 月 25 日
dear Geoff sorry for being late..i was not around for a while. i downloaded again and i paste the code in command window and it runs. thanks alot take care
cathrin philo
2016 年 2 月 9 日
can anyone give the matlab code for cellular automata (rule 30) with image as input? Thanks in advance.
Geoff Hayes
2016 年 2 月 10 日
Catherine - please post this as a separate question and be clear about what you want. Clarify why the wolfram code from the File Exchange (discussed above) does not meet your need for rule 30, and clarify what you mean by with image as input.
cathrin philo
2016 年 2 月 17 日
Thank you for your reply. my task is to apply rule 30 to any of the image. how can i proceed with this problem?
Geoff Hayes
2016 年 2 月 17 日
To any what of the image? A row or column? Is your image grayscale or RGB?
cathrin philo
2016 年 2 月 18 日
the image i have taken is an DICOM grayscale image. rule can be applied to either row or column.
Geoff Hayes
2016 年 2 月 20 日
Cathrin - I suspect that you would call the wolfram function as
wolfram(30, myRowOrCol, nRowsOrCols)
where myRowOrCol is the row or column from your image that you want to apply the rule to, and nRowsOrCols is the number of rows or columns that you want to "create". You may need to update the wolfram function so that it returns the output which you can then copy into the image (if that is what you are trying to do?).
cathrin philo
2016 年 2 月 22 日
編集済み: Geoff Hayes
2016 年 2 月 23 日
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
2016 年 2 月 23 日
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);
その他の回答 (0 件)
カテゴリ
ヘルプ センター および File Exchange で Matrix Indexing についてさらに検索
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Web サイトの選択
Web サイトを選択すると、翻訳されたコンテンツにアクセスし、地域のイベントやサービスを確認できます。現在の位置情報に基づき、次のサイトの選択を推奨します:
また、以下のリストから Web サイトを選択することもできます。
最適なサイトパフォーマンスの取得方法
中国のサイト (中国語または英語) を選択することで、最適なサイトパフォーマンスが得られます。その他の国の MathWorks のサイトは、お客様の地域からのアクセスが最適化されていません。
南北アメリカ
- América Latina (Español)
- Canada (English)
- United States (English)
ヨーロッパ
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
