Hi,
Say I have an array of index variables gained from sorting out data:
i.e. row = [1 2 3 4 6 7 8 10 11 12]
I'd like to split this array into different columns at where its not incrementing consecutively.
I've made a start
for i=1:length(row)-1;
if row(i+1) ~= row(i)+1;
{split row array into a different column}
end
end
Essentially I want my output to look like:
output = [1 2 3 4; 6 7 8; 10 11 12]

답변 (2개)

Walter Roberson
Walter Roberson 2014년 3월 26일

0 개 추천

You cannot do that. Numeric arrays in MATLAB must have the same number of rows and columns for all entries.
You could use a cell array but not a numeric array.

댓글 수: 1

Isuru
Isuru 2014년 3월 26일
You're right. How would I do this using a cell array?

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

Azzi Abdelmalek
Azzi Abdelmalek 2014년 3월 26일

0 개 추천

a= [1 2 3 4 6 7 8 10 11 12]
s=[[2 diff(a)]==1 0]
out=arrayfun(@(x,y) a(x:y),strfind(s,[0 1]),strfind(s,[1,0]),'un',0);
celldisp(out)

카테고리

도움말 센터File Exchange에서 Operators and Elementary Operations에 대해 자세히 알아보기

태그

질문:

2014년 3월 26일

답변:

2014년 3월 26일

Community Treasure Hunt

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

Start Hunting!

Translated by