How to pad cell w/ multiple arrays with zeros

조회 수: 7 (최근 30일)
m j
m j 2020년 7월 27일
댓글: m j 2020년 7월 28일
Hello,
I have a cell array: myCell = {1,4}, each array inside the cell can be:
ex:
1500X1
2000X1
2048X1
3400X1
I would like to pad all arrays that dont equal max array length(3400) with zeros and plot. Im trying to use cellfun but am having trouble padding.I can find the max using cellfun easy with:
[s,d] = cellfun(@size,myCell);
outputMax = max([s,d]);
But am having trouble figuring out how to use cellfun ,now that I know what the MAX length is of my arrays....I tried padarray but failed miserably.Any ideas?
Thanks

채택된 답변

madhan ravi
madhan ravi 2020년 7월 27일
편집: madhan ravi 2020년 7월 27일
M = max(cellfun(@length, myCell));
Wanted = cellfun(@(x) [x; zeros(M - numel(x), 1)], myCell, 'un', 0)
  댓글 수: 4
madhan ravi
madhan ravi 2020년 7월 28일
I answered your original question.
m j
m j 2020년 7월 28일
You are correct,I accepted answer and asked question elsewhere.Thanks!

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

추가 답변 (0개)

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by