Sorting out raw index from raw data
10 views (last 30 days)
Show older comments
Hi Everyone
I have some cyclic data which is similar to the attached.
The data is from creep fatigue data, you can regard 1 as fatigue and 0 as creep,
what I want to achieve is as follows
with only raw data given
first define the range of each cycle
then for each cycle I would like to sort out the row index or range of both fatigeu and Creep Portion
I am achieve an example through excel by eyeball but could not find a way with matlab as there is lot of data to sort.
Can anyone help me with this problem?
Thank you very much

0 Comments
Accepted Answer
Dave B
on 11 Aug 2021
A trick to these kinds of problems is to combine find and diff, diff is good at marking the transitions between states and find is good at turning those into row numbers.
One thing to watch out for - you'll probably need to check the initial and final state, this code assumes that the initial state is a 1 and the final state is a 0, but the more general case would check these and adapt...I'll leave that part up to you.
% copy of your data
x=[1 1 1 0 0 1 1 1 0 0 0 0 1 1 1 0 0];
% note that really you only need to call find twice, the repeats are just to make it look similar
oneA=find(diff([0 x])==1);
oneB=find(diff([0 x])==-1)-1;
oneC=find(diff([0 x])==-1);
oneD=find(diff([x 1])==1);
disp([oneA;oneB;oneC;oneD])
More Answers (0)
See Also
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!