rearranging the data in separate columns when difference of 10 is found in vector

I have data like: 1,2,3,4,5,7,8,11,13,14,15,17,18,19,21,23,24,25...36..,
Here, I would like to divide this series into columns as soon as the difference of ten from the initial number is found in the vector. I.e: Column one will contain, 1,2,3,4,5,7,8,11 and Column 2 will 13,14,15,17,18,19,21,23,24 and third column the values from 25...36 and so forth.
Any hints or example code would be highly helpful.

 Akzeptierte Antwort

You cannot do that. Your columns have different lengths, and numeric matrices must always use the same length for rows and columns.
You could use a cell array.
The difference of 10: is that relative to the very first value in the vector (1 in this case), or is it relative to the last break value? For example if the break value had been (say) 12, would the offset of 10 start from 21 (initial 1 + a multiple of 10) or from 22 (difference of 10 from the last break) ?
I do not understand why 24 is to be in the vector that starts at 13 ? The difference of 10 from the 13 would be 23 so why isn't the 23 the end of that run?

Weitere Antworten (1)

DJ_LAB
DJ_LAB am 6 Feb. 2012
Hello Walter,
Thank you very much for your response,
*The difference of 10: is that relative to the very first value in the vector (1 in this case), or is it relative to the last break value?
Its relative to last break value. i.e. first relative value would be 1, second 13, third 24 and so on.
*why isn't the 23 the end of that run?and pointing out
Sorry for it, It should be as you said.
Column one will contain, 1,2,3,4,5,7,8,11 and Column 2 will 13,14,15,17,18,19,21,23 and third column the values from 24...34 and so forth.
These can also be copied in independent matrices, say: A, B, C, D... and each contains vector whose first value and last value differ by 10. But, size of A,B,C,D... need not be identical.
Thanks again Any hints?

Kategorien

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by