How to split array which is discontinuous and plot them?

조회 수: 2 (최근 30일)
Josh Hwa
Josh Hwa 2019년 4월 26일
댓글: Josh Hwa 2019년 4월 26일
I have a se of array like 'a' and I would like to split them into
[1 2 3 4 5 6 7 8 9]
[17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42]
[50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73]
[79 80 81 82 83 84 85 86 87 88]
Then, it can be plot by using plot(x(a),y(a),'-')
I have go through the split array question but it cant work on these kind of array.
Can someone guide me on this? Will be much appreciate.
a=[1 2 3 4 5 6 7 8 9 17 18 19 20 21 22 23 24 25 26 27 28 29 30
31 32 33 34 35 36 37 38 39 40 41 42 50 51 52 53 54 55 56 57 58 59 60
61 62 63 64 65 66 67 68 69 70 71 72 73 79 80 81 82 83 84 85 86 87 88]

답변 (1개)

KSSV
KSSV 2019년 4월 26일
a=[1 2 3 4 5 6 7 8 9 17 18 19 20 21 22 23 24 25 26 27 28 29 30
31 32 33 34 35 36 37 38 39 40 41 42 50 51 52 53 54 55 56 57 58 59 60
61 62 63 64 65 66 67 68 69 70 71 72 73 79 80 81 82 83 84 85 86 87 88] ;
a = a' ; a = a(:)' ;
L = [9 26 24 10] ; % required lengths
C = mat2cell(a,1,L);
  댓글 수: 1
Josh Hwa
Josh Hwa 2019년 4월 26일
Hi, your code works so fine but the length might be unknown as im using ginput. the 'a' array is just an example. Can it be done without knowing the length? Appreciate..

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

카테고리

Help CenterFile Exchange에서 Resizing and Reshaping Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by