Filter löschen
Filter löschen

How to split an array

1 Ansicht (letzte 30 Tage)
Isuru
Isuru am 26 Mär. 2014
Beantwortet: Azzi Abdelmalek am 26 Mär. 2014
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]

Antworten (2)

Walter Roberson
Walter Roberson am 26 Mär. 2014
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 Kommentar
Isuru
Isuru am 26 Mär. 2014
You're right. How would I do this using a cell array?

Melden Sie sich an, um zu kommentieren.


Azzi Abdelmalek
Azzi Abdelmalek am 26 Mär. 2014
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)

Kategorien

Mehr zu Multidimensional Arrays finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by