convert logical cell array to double

조회 수: 6 (최근 30일)
AP
AP 2011년 6월 4일
I have a 4×1 logical cell array and each element is also a 2×1 cell array. So there are 8 elements total. I want to convert them all to double and vertically merge them. I tried the following but I couldn't:
cellfun(@(x) vertcat(double(x)), mycell,'uni',0)
the error is:
??? Error using ==> double
Conversion to double from cell is not possible.
  댓글 수: 2
the cyclist
the cyclist 2011년 6월 4일
It is not 100% clear to me what you mean by a "logical cell array", or quite what the contents look like. Is it that mycell is a 4x1 cell array, and the content of each of the four elements is a 2x1 cell array, and the contents of each element of those 2x1's is a logical scalar? Would it be possible for you to include an example of "mycell", to be clearer?
Any chance you could change the construction of the variables upstream, so that it is not so convoluted?
AP
AP 2011년 6월 4일
What you understand is exactly correct. mycell is 4×1 cell array. each element of mycell contains two 69×79 logical array which make total of 8 element.

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

답변 (3개)

Walter Roberson
Walter Roberson 2011년 6월 4일
0 + cell2mat(vertcat(mycell{:}))
  댓글 수: 6
Walter Roberson
Walter Roberson 2011년 6월 5일
60 x 63 is not a fit horizontally or vertically.
How do you want to proceed from here?
Also, do you want the result to be N x 79, or N x (79 * 2)? It isn't clear whether you want the groups of 2 x 1 to be arranged vertically (giving N x (79 * 2)), or if you want everything to be stacked as if a single N x 79 array? If everything is to be stacked, you need to define the relative order for the pieces.
Jan
Jan 2011년 6월 6일
@Walter: You can omit the "0" in "0+cell2mat(vertcat(mycell{:}))". "+TRUE" is a DOUBLE.

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


Matt Fig
Matt Fig 2011년 6월 4일
If A is your array,
B = [A{:}]; % Step 1.
B = [B{:}] % Step 2.
This will only work if each of the logical arrays in each cell are the same size in the row direction. If instead they are all the same size in the column direction, try this:
B = [A{:}]; % Step 1.
B = vertcat(B{:}) % Step 2.

the cyclist
the cyclist 2011년 6월 4일
output = cell2mat(cellfun(@cell2mat,mycell,'UniformOutput',false))
  댓글 수: 1
AP
AP 2011년 6월 4일
??? Error using ==> cat
CAT arguments dimensions are not consistent.
Error in ==> cell2mat at 89
m{n} = cat(1,c{:,n});

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

카테고리

Help CenterFile Exchange에서 Data Type Conversion에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by