Scramble the positions of a cell array

1 回表示 (過去 30 日間)
Abirami
Abirami 2014 年 8 月 21 日
回答済み: Azzi Abdelmalek 2014 年 8 月 21 日
I have two cell array as follows
Z= (2,5) (2,3) (2,1) (2,2) (2,4)
(4,5) (4,3) (4,1) (4,2) (4,4)
(5,5) (5,3) (5,1) (5,2) (5,4)
(3,5) (3,3) (3,1) (3,2) (3,4)
(1,5) (1,3) (1,1) (1,2) (1,4)
W= 'ATGC' 'ACTG' 'AGCT' 'AATT' 'TATG'
'GCTA' 'GACT' 'TACG' 'TGAT' 'ATAT'
'TCGG' 'CATA' 'TAAT' 'TTTT' 'CTGC'
'AAGT' 'AAGG' 'TGGG' 'TGTA' 'CAAA'
'GTGG' 'CTCT' 'GATT' 'CGTG' 'CTGG'
Now i have a big problem....i need to create a new cell array 'G' where the value of W should be placed accprding to the positions given in Z.
For eg: the value ATGC (ie;the first element of W) should be placed at (2,5) of 'G'. Both the cell arrays are just examples...i need to do it for a 256*256 array. Please help.Thanks in advance

採用された回答

Azzi Abdelmalek
Azzi Abdelmalek 2014 年 8 月 21 日
Z= {[2,5] [2,3] [2,1] [2,2] [2,4]
[4,5] [4,3] [4,1] [4,2] [4,4]
[5,5] [5,3] [5,1] [5,2] [5,4]
[3,5] [3,3] [3,1] [3,2] [3,4]
[1,5] [1,3] [1,1] [1,2] [1,4]}
W={ 'ATGC' 'ACTG' 'AGCT' 'AATT' 'TATG'
'GCTA' 'GACT' 'TACG' 'TGAT' 'ATAT'
'TCGG' 'CATA' 'TAAT' 'TTTT' 'CTGC'
'AAGT' 'AAGG' 'TGGG' 'TGTA' 'CAAA'
'GTGG' 'CTCT' 'GATT' 'CGTG' 'CTGG'}
out=cellfun(@(x) W{x(1),x(2)},Z,'un',0)

その他の回答 (1 件)

Michael Haderlein
Michael Haderlein 2014 年 8 月 21 日
Dear Abirami,
one possibility:
ind=cellfun(@(x) sub2ind(size(Z),x(1),x(2)),Z);
[~,s]=sort(ind(:));
G=reshape(W(s),size(Z));
Best regards,
Michael

カテゴリ

Help Center および File ExchangeHistograms についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by