divide the matrix to blocks

I need to divide matrix to blocks have size (1*3) how can write (for loop) to get blocks as the following example
matrix = [1 4 3 5 7 1;4 2 1 5 4 7;8 0 1 4 5 6] I need first block = [1 4 3] second block = [5 7 1] third block = [4 2 1]
and so on

 채택된 답변

Matt J
Matt J 2013년 4월 25일

0 개 추천

댓글 수: 5

Matt J
Matt J 2013년 4월 25일
편집: Matt J 2013년 4월 25일
In your case, it would apply as follows,
result=mat2tiles(yourMatrix,[1,3]);
Aseel H
Aseel H 2013년 4월 25일
it is OK, but how i can deal with the values of each cell
by meanning, I need to make some operation on the first values of all cells as multiple it by constant as 4 i.e the first cell will become = 4,4,3 the second cell will become = 20,7,1 and so on
It was never necessary to split the matrix into blocks, for that. All you needed to do was
matrix(:,1:3:end) = 4*matrix(:,1:3:end);
For more complicated things, you can use the CELLFUN command, or BLOCKPROC.
Aseel H
Aseel H 2013년 4월 26일
No, I can not use matrix(:,1:3:end) = 4*matrix(:,1:3:end); because I need deal with values of each block alone,for example
X = [5 6 4 7 9 8;5 0 1 4 7 3];
after that: cell1 = [5,6,4] cell2 = [7,9,8] and do on
After that will be execute some operations on the values of each individual cell, according to some conditions if they apply to the three values in each cell or not
In other words how I call on the values of each cell
The first value of cell one the second value of cell one ......... etc
Matt J
Matt J 2013년 4월 26일

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Aseel H
Aseel H 2013년 4월 25일
편집: Matt J 2013년 4월 25일

0 개 추천

Deleted by Matt J

질문:

2013년 4월 25일

Community Treasure Hunt

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

Start Hunting!

Translated by