필터 지우기
필터 지우기

Build an array with different column lengths

조회 수: 15 (최근 30일)
matlabuser12
matlabuser12 2016년 8월 15일
편집: Matt J 2016년 8월 15일
Have one large data set (3333x1 double) and am trying to section out rows based on certain index values. If I have say 10 index pairs (beginning and end row) that I want to section out,each with different lengths how can I build one new nx10 matrix?
I keep getting subscripted assignment mismatches and similar errors when I try things like:
for i = 1:length(indices)
newData(:,i) = olddata(indexstart(i):indexstop(i),:);
end

답변 (1개)

Matt J
Matt J 2016년 8월 15일
편집: Matt J 2016년 8월 15일
Usually you would store such a result as a cell array,
newData=cell(1, length(indices));
for i = 1:length(indices)
newData{i} = olddata(indexstart(i):indexstop(i));
end
If it needs to be a numeric array, you need to decide what will go in the missing spots.
  댓글 수: 4
matlabuser12
matlabuser12 2016년 8월 15일
I get a 1x10 array with each cell having one column in it. do I need to nest this newdata into another cell array or something?
Matt J
Matt J 2016년 8월 15일
편집: Matt J 2016년 8월 15일
Your needs, and what you plan to do with this data later, are completely hidden from me. However, I can't imagine many situations where you couldn't use the 1x10 cell array as is.

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

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by