split matrix into matrices with rows in same range
Show older comments
I have a matrix A as below:
a = [20 30 45 55 100; 200 150 175 60 20; 100 29 36 52 98; 28 33 48 62 95; 206 147 180 53 45];
I want to have matrices with rows in range of +/-10 and if one number of each rows are out of range, it's okay.
For example, for matrix A we can write:
B = [20 30 45 55 100; 100 29 36 52 98; 28 33 48 62 95]
C = [200 150 175 60 20; 206 147 180 53 45]
for example if I have a matrix 1000*2000 how can I split it?
1 Comment
John D'Errico
on 19 Mar 2017
Edited: John D'Errico
on 19 Mar 2017
Don't do it that way. Creating piles of separately named matrices from one is just a bad idea. It will create a mess of inefficient, buggy code. Instead, learn what a cell array is. Extract each piece into one cell of the cell array.
https://www.mathworks.com/matlabcentral/answers/304528-tutorial-why-variables-should-not-be-named-dynamically-eval
As far as how to do the actual identification of what rows belong in one set or another, you need to be far more specific about your goals. A mathematical algorithm requires a specific set of clear rules. Otherwise, you will get random junk for a result.
Accepted Answer
More Answers (0)
Categories
Find more on Lengths and Angles in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!