Suppose I have this:
v= {1 8 1 1 6 1 2 5 3 2 7 11 7 9 10 9};
How can I mat them as below? ( with array start and end as same number)
v= { [1 8 1] [1 6 1] [2 5 3 2] [7 11 7] [9 10 9] };

 채택된 답변

Stephen23
Stephen23 2019년 4월 29일
편집: Stephen23 2019년 4월 29일

0 개 추천

>> v = {1,8,1,1,6,1,2,5,3,2,7,11,7,9,10,9};
>> c = regexp(char([v{:}]),'(.).*?(??$1)','match');
>> c = cellfun(@double,c,'uni',0);
>> c{:}
ans =
1 8 1
ans =
1 6 1
ans =
2 5 3 2
ans =
7 11 7
ans =
9 10 9

댓글 수: 1

Hang Vu
Hang Vu 2019년 4월 29일
Thank you so much!^^ you saved me 2 times. I just re-asked for previous question. Could you please take a look if you have time!

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

추가 답변 (1개)

Andrei Bobrov
Andrei Bobrov 2019년 4월 29일

0 개 추천

out = mat2cell([v{:}],1,[3,3,4,3,3]);

댓글 수: 1

Hang Vu
Hang Vu 2019년 4월 29일
편집: Hang Vu 2019년 4월 29일
Thank you for the response!

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

카테고리

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

질문:

2019년 4월 29일

편집:

2019년 4월 29일

Community Treasure Hunt

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

Start Hunting!

Translated by