how to make all vectors to equal size for a cell array.

조회 수: 5 (최근 30일)
Sandhu
Sandhu 2011년 10월 10일
편집: per isakson 2017년 12월 1일
hi, i have a cell array of z{k}, it has totally 60 cells. which are diffident size in columns. so while i am trying to plot all arrays data in a single plot,[plot(z{1}) it works for one cell.] it says all vectors must have same size.
plot(z{:})
??? Error using ==> plot
Vectors must be the same lengths.
so, i want to make equal size of vectors by placing zeros. so any one can please help me.

채택된 답변

Fangjun Jiang
Fangjun Jiang 2011년 10월 10일
It might be easier using a for-loop, with hold on;
figure;hold on;
for k=1:length(z)
plot(z{k});
end

추가 답변 (1개)

Laura Proctor
Laura Proctor 2011년 10월 10일
lv = max(cellfun(@length,z));
za = zeros(1,lv);
for idx = 1:length(z)
cellVal = z{idx};
if length(cellVal) < lv
z{idx} = za;
z{idx}(1:length(cellVal)) = cellVal;
end
end
  댓글 수: 2
Sandhu
Sandhu 2011년 10월 10일
tnq very much for help. it also works. tnx alot.
Mansour Aljohani
Mansour Aljohani 2015년 8월 20일
Thank you so much Laura

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

카테고리

Help CenterFile Exchange에서 Operators and Elementary Operations에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by