Hi everyone,
i have an array like this:
A
0.5 0.4 0.5
0.9 0.3 0.5
0.5 0.5 0.1
0.5 0.4 0.2
0.9 0.8 0.2
0.3 0.5 0.2
and i want to create a cell arrays like these (group all the columns every N rows, with N=2):
{A1}
0.5 0.4 0.5
0.9 0.3 0.5
{A2}
0.5 0.5 0.1
0.5 0.4 0.2
{A3}
0.9 0.8 0.2
0.3 0.5 0.2
How can i do it?
Thank you very much!

 채택된 답변

madhan ravi
madhan ravi 2019년 1월 24일
편집: madhan ravi 2019년 1월 24일

1 개 추천

Your way:
N=2;
A=mat2cell(a,repelem(N,size(a,1)/N));
celldisp(A)

추가 답변 (1개)

madhan ravi
madhan ravi 2019년 1월 24일
편집: madhan ravi 2019년 1월 24일

0 개 추천

One way:
N=2;
[~,c]=size(A);
U=reshape(A',c,N,[]);
R=permute(U,[2 1 3])

댓글 수: 4

Riccardo Rossi
Riccardo Rossi 2019년 1월 29일
I'm sorry if i have an array like this:
0.4 0.9 0.4 0.7 0.2 0.01 0.2 0.7
how can i permute the array in another like this?:
0.4 0.9 0.4 0.7
0.2 0.01 0.2 0.7
Thank you!
reshape(a,numel(a)/2,[])' % where a your array
Riccardo Rossi
Riccardo Rossi 2019년 1월 29일
Sorry but it does not run. I improve my example. I have an array like this:
1 2 3 4 5 6 7 8
9 10 11 12 13 14 15 16
17 18 19 20 21 22 23 24
25 26 27 28 29 30 31 32
how can i permute the array in another like this?:
1 2 3 4
9 10 11 12
17 18 19 20
25 26 27 28
5 6 7 8
13 14 15 16
21 22 23 24
29 30 31 32
Thank you so much!
I see you have asked another question regarding this issue but here is one solution:
N=4;
[m,c]=size(A);
U=reshape(A',m,[],N);
R=permute(U,[1 3 2]);
BB=reshape(R,N,[],1)'

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

카테고리

도움말 센터File Exchange에서 Matrix Indexing에 대해 자세히 알아보기

제품

릴리스

R2018b

질문:

2019년 1월 24일

댓글:

2019년 1월 29일

Community Treasure Hunt

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

Start Hunting!

Translated by