필터 지우기
필터 지우기

splitting up numbers in a cell of a double

조회 수: 5 (최근 30일)
Abbey Stock
Abbey Stock 2020년 10월 13일
편집: Star Strider 2020년 10월 13일
Hi,
I have a 22x1 double array with numbers such as 0100001 0100100 in each cell. How would i split this up into a 154x1 (22*7) vector with
0
1
0
0
0
0
1
0
1
0
0
1
0
0
etc

답변 (2개)

Star Strider
Star Strider 2020년 10월 13일
편집: Star Strider 2020년 10월 13일
See if the num2cell function will do what you want.
EDIT — (13 Oct 2020 at 12:53)
(Question was essentially completely changed.)
To clarify, it is not a double array, because the leading zeros would not be present. Most likely is’s a cell array:
v = {'0100001' '0100100'};
and it’s relatively straightforward (although not at all obvious) to get the result you want:
Out = reshape([v{:}]-'0', [],1)
producing:
Out =
0
1
0
0
0
0
1
0
1
0
0
1
0
0
.
  댓글 수: 4
Abbey Stock
Abbey Stock 2020년 10월 13일
편집: Abbey Stock 2020년 10월 13일
hi,
The way with {;} produced an error but when using reshape([x]-'0', 1,[]); it reads down the rows instead of across the columns, so i end up with 0 0 1 1 etc instead of 01.. 01..
Star Strider
Star Strider 2020년 10월 13일
편집: Star Strider 2020년 10월 13일
Brace indexing would not work for a double array, only a cell array.
Something is not correct, since a double would not have leading zeros.
It would help to see the actual original data, most likely as a .mat file.
(13:12 UCT) With respect to your edited Comment, I am now thoroughly lost. I have no idea what your data actually are, much less how to deal with what appears to be a moving target.

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


madhan ravi
madhan ravi 2020년 10월 13일
편집: madhan ravi 2020년 10월 13일
Wanted = vertcat(cell_array{:})
%or
Wanted = cat(1, cell_array{:})
  댓글 수: 2
Abbey Stock
Abbey Stock 2020년 10월 13일
hi, i just get 'Brace indexing is not supported for variables of this type'
madhan ravi
madhan ravi 2020년 10월 13일
편집: madhan ravi 2020년 10월 13일
cell_array = {[0,1,0,0,0,0,1].', [0,1,0,0,1,0,0].'};
Wanted = vertcat(cell_array{:})
%or
Wanted = cat(1, cell_array{:})

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

카테고리

Help CenterFile Exchange에서 Structures에 대해 자세히 알아보기

제품


릴리스

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by