Sorting out raw index from raw data

10 vues (au cours des 30 derniers jours)
ZHE LYU
ZHE LYU le 11 Août 2021
Commenté : ZHE LYU le 11 Août 2021
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

Réponse acceptée

Dave B
Dave B le 11 Août 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])
1 6 13 3 8 15 4 9 16 5 12 17
  1 commentaire
ZHE LYU
ZHE LYU le 11 Août 2021
Thank you so much!

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Logical dans Help Center et File Exchange

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by