I want to plot non-zero consecutive segments from an array
3 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I have a data which contains zero and non-zero values in segments like [0 0 0 1 2 3 0 0 0 0 8 9 6]. I want to plot the non-zero values which are in sequence like [1 2 3] and [8 9 6] separately.
0 commentaires
Réponses (1)
Walter Roberson
le 7 Oct 2021
Modifié(e) : Walter Roberson
le 7 Oct 2021
A = [0 0 0 1 2 3 0 0 0 0 8 9 6]
starts = strfind([false, logical(A)], [0 1])
stops = strfind([logical(A), false], [1 0])
hold on
arrayfun(@(B,E) plot(B:E, A(B:E), '-*'), starts, stops);
hold off
xlim auto; ylim auto
2 commentaires
Walter Roberson
le 7 Oct 2021
A = [0 0 0 1 2 3 0 0 0 0 8 9 6]
starts = strfind([false, logical(A)], [0 1])
stops = strfind([logical(A), false], [1 0])
arrayfun(@(B,E) plot(gca(figure()), B:E, A(B:E), '-*'), starts, stops);
Voir également
Catégories
En savoir plus sur 2-D and 3-D Plots dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!