MATLAB Answers

Assign values in the cell

조회 수: 5(최근 30일)
Turbulence Analysis
Turbulence Analysis 2021년 7월 16일
댓글: Rik 2021년 7월 16일
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일
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.
  댓글 수: 3
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{:});

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

추가 답변(0개)

Community Treasure Hunt

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

Start Hunting!

Translated by