フィルターのクリア

Cell arrays with a vector within a cell within a cell

3 ビュー (過去 30 日間)
L'O.G.
L'O.G. 2023 年 5 月 7 日
コメント済み: L'O.G. 2023 年 5 月 9 日
I have a cell array where each element consists of a 1 x 1 cell containing a vector of type double, i.e., C{1,1} contains a vector of length N.
How do I convert the inner cells from 1 x 1 cells into N x 1 cells where the entries correspond to each vector of length N? The N of each vector might be different.
I think the right way to do this is via cellfun but something like
C_out = cellfun(@(C_test) num2cell(C_test{1}), C_in, 'uniform',0);
does not quite get me there.

採用された回答

Matt J
Matt J 2023 年 5 月 9 日
Maybe this is what you mean?
C_in={[1;2;3],[4;5],6}
C_in = 1×3 cell array
{3×1 double} {2×1 double} {[6]}
n=max(cellfun('length',C_in));
C_out=num2cell(cell2mat( cellfun(@(x) cpad(x,n), C_in,'uni',0) ) )
C_out = 3×3 cell array
{[1]} {[ 4]} {[ 6]} {[2]} {[ 5]} {[NaN]} {[3]} {[NaN]} {[NaN]}
function C=cpad(C,n)
C(end+1:n,1)=nan;
end

その他の回答 (2 件)

Walter Roberson
Walter Roberson 2023 年 5 月 7 日
cellfun up a num2cell call.
  1 件のコメント
L'O.G.
L'O.G. 2023 年 5 月 7 日
編集済み: L'O.G. 2023 年 5 月 8 日
What does "cellfun up" mean? I think that's what I tried to do as I mention in my question.

サインインしてコメントする。


Matt J
Matt J 2023 年 5 月 9 日
編集済み: Matt J 2023 年 5 月 9 日
Is this what you mean?
C_in={{[1;2;3]},{[4;5]},{6}}
C_in = 1×3 cell array
{1×1 cell} {1×1 cell} {1×1 cell}
C_out=[C_in{:}]
C_out = 1×3 cell array
{3×1 double} {2×1 double} {[6]}

カテゴリ

Help Center および File ExchangeProgramming についてさらに検索

製品


リリース

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by