Hi,
I have the 72 x 1 cell named output 1 (attached here).
As shown in the attachment, some cells got empty matrix, I intend to add zero values in the manner of 8x1 into all the all empty cells ..
Any idea how to assign this .. ??

 採用された回答

Rik
Rik 2021 年 7 月 16 日
編集済み: Rik 2021 年 7 月 16 日

0 投票

You mean like this?
output1={[1 2;3 4],[]};
L=cellfun(@isempty,output1);
output1(L)={zeros(8,1)};
output1
output1 = 1×2 cell array
{2×2 double} {8×1 double}
Note that cellfun has a legacy mode, which is often much faster, but is limited in terms of what data types will work.

5 件のコメント

Turbulence Analysis
Turbulence Analysis 2021 年 7 月 16 日
Exactly !!!!!!!.. Perfect thanks a lot .. !!
Turbulence Analysis
Turbulence Analysis 2021 年 7 月 16 日
Just one follow up question, now each cell got 8,1 entires, I am looking to store each 8 x 1 entries as single column in the seperate matrix. I just tried cell2mat (output1), However it stores all the entries of cell in the single column..
Rik
Rik 2021 年 7 月 16 日
You can either use reshape to make sure your cell array is a row vector, or use horzcat and a comma separated list:
mat=horzcat(output1{:});
Amir Pasha Zamani
Amir Pasha Zamani 2022 年 4 月 25 日
It only works for a single element of the cell.
I need to pre-assign values (let's say zeros(10,10)) to all cell elemenst.
Rik
Rik 2022 年 4 月 25 日
@Amir Pasha Zamani L can be a logical array with as many elements as output1 (or fewer). So can you explain what you mean?
To pre-allocate the array you describe I suggest using repmat or repelem:
YouWant=repmat({zeros(10,10)},2,3)
YouWant = 2×3 cell array
{10×10 double} {10×10 double} {10×10 double} {10×10 double} {10×10 double} {10×10 double}

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

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeData Type Conversion についてさらに検索

質問済み:

2021 年 7 月 16 日

コメント済み:

Rik
2022 年 4 月 25 日

Community Treasure Hunt

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

Start Hunting!

Translated by