Inserting an array in another to make an Nested Array

Hello I want to build a fractal. I want to start with One=[1 0 1;0 0 0;1 0 1] Zero=zeros(3)
Then I want to search this array for an element =1 if equal to "1" insert the array One otherwise the array Zero. I am pretty sure this can be done with Cat but wanted to see what others think.
Thanks for your time.

2 件のコメント

James Tursa
James Tursa 2015 年 2 月 27 日
Please provide a complete example of inputs and desired output. "insert the array" really doesn't tell us much about what you really want.
thiirane
thiirane 2015 年 2 月 28 日
Hmmm. OK let me try again. My generator array is called "One" One= [1 0 1;0 0 0;1 0 1];
The next level fractal is where One is inserted in every element of "One" where "1" exists. If the element contains a "0" then the array Zero is inserted into One. Zero=zero(3); I am simply looking for a simple way to nest One and Zero into my generator array.

サインインしてコメントする。

 採用された回答

Guillaume
Guillaume 2015 年 2 月 28 日

3 投票

C = {zeros(3); [1 0 1; 0 0 0; 1 0 1]};
X = [1 1 0; 0 1 0]; %current matrix
X = cell2mat(C(X+1)) %new matrix

2 件のコメント

thiirane
thiirane 2015 年 2 月 28 日
Can you help me understand how cell2mat used in this way works? How does cell2mat interpret C(X+1)?
Guillaume
Guillaume 2015 年 2 月 28 日
It's fairly basic indexing, Y = C(X) returns an array Y the size of X (*) where each element Yn is the value of C at index Xn.
Therefore, in C(X+1), when Xn == 0, Yn is C(1) and when Xn == 1, Yn is C(2).
* except under some circumstances (both are vectors) because people at Mathworks love having exceptions which we all know makes generic programming so much easier. /end rant

サインインしてコメントする。

その他の回答 (1 件)

Roger Stafford
Roger Stafford 2015 年 2 月 28 日
編集済み: Roger Stafford 2015 年 2 月 28 日

2 投票

ONE = [1 0 1;0 0 0;1 0 1];
M = (your current matrix of 1's and 0's)
M = kron(M,ONE); % This will be the next version of M

カテゴリ

ヘルプ センター および File ExchangeResizing and Reshaping Matrices についてさらに検索

タグ

質問済み:

2015 年 2 月 27 日

コメント済み:

2015 年 2 月 28 日

Community Treasure Hunt

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

Start Hunting!

Translated by