Problem splitting large array into smaller arrays
Show older comments
I am trying to split my (n,5) array into smaller sections based on my 4th column. This column makes the data move in a sort of sine wave motion (peak to zero to valley to zero to peak...to zero to valley).
I am trying to split my data in the following manner: (where I want each color line to signify a new array)

(Plot:
plot(data(:,1),data(:,2)
)
For this, I am creating a loop that evaluates the conditions of column 4 and adds the data to a new array. As my first coding step I took the data and tried to separate them such that if the value on column 4 >= 0 then it would add them to a new array. So far I have:
new = [];
other = [];
pos = data(:,4);
x=1:1:5;
for ii = 1;
if (data(:,4)>=0)
new(ii) = [new,data(:,x)];
else
other(ii) = [other, data(:,x)];
end
end
However, doing this isn't working. It's just rewriting my original data set to a new variable. Is what I'm trying to do possible? Would it be better to do it without a loop (if possible)?
(I am trying to make this code as general as possible because the length of my sections (as seen in the image) will not always be the same.)
I attached a .txt file with my data, in case my explanation doesn't make sense.
Thank you in advance.
Accepted Answer
More Answers (0)
Categories
Find more on Logical in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!