segmentation matlab code
Predictor said:
shaikh105 said:
i want to capture following series of numbers into segments
as the series of numbers below show 4 segments
ie.
seg1= 1 2 3
seg2= 10 11 12 13
seg3= 90 91
seg4= 100 101 102 103 104 105 106
.............................upto seg(N)
i need help in making matlab code that searches such "seg" from within the "vector" and stores them individually as seg1, seg2, seg3,,,,seg(N).
can any body help me plz
If I understand what you need, then I'd suggest something that begins with:
% Set threshold for distance between segments
threshold = 5;
% Generate vector of segment labels
SegmentLabel = cumsum([1 diff(vector) > threshold])
SegmentLabel =
1 1 1 2 2 2 2 3 3 4 4 4 4 4 4 4
Picking out the individual segments should be easy, from this point:
>> seg1 = vector(SegmentLabel == 1)
seg1 =
1 2 3
>> seg2 = vector(SegmentLabel == 2)
seg2 =
10 11 12 13
...and so on.
-Will
https://matlabdatamining.blogspot.com/
its nice ,, i am greatful but there iz one problem i want to incorporate a loop as u can see below:
d1 is my vector
i want to get seg1, seg 2,,,,,,,,,,, by doing as below,,, but it is working as below but not as ""seg(jk)""
because segjk gives the last segment of my vector d1,,, whereas i need the loop run and finally gives me all these and as many segments seg1 , seg2 ,seg3,,,, seg(N) present in my vector d1,,,,,,,,,, i hope i conveyed my problem . i am thankful for ur knd help
regards
threshold = 5;
% Generate vector of segment labels
SegmentLabel = cumsum([1 diff(d1) > threshold]);
for jk=1:max(SegmentLabel)
segjk = d1(SegmentLabel == jk);
end