Effacer les filtres
Effacer les filtres

Create a new array everytime with the change of sign in an array

1 vue (au cours des 30 derniers jours)
Sri Vishnu Katreddi
Sri Vishnu Katreddi le 29 Avr 2022
Modifié(e) : Matt J le 29 Avr 2022
I have an array A = [0 1 2 3 2 1 0 -1 -2 -2 -1 0 1 1.6 1.8 2 1 0 .... ], Now I want to create a new array everytime the sign changes in the array, it should look like
B = [0 1 2 3 2 1 0]
C = [-1 -2 -2 -1]
D = [0 1 1.6 1.8 2 1 0]
.
.
.
  2 commentaires
Walter Roberson
Walter Roberson le 29 Avr 2022
Why should it look like that? sign(0) is not the same as sign(1) . Why are you including 0 in the run of positives? Why does the 0 not get included with the run of negatives?
Sri Vishnu Katreddi
Sri Vishnu Katreddi le 29 Avr 2022
Modifié(e) : Sri Vishnu Katreddi le 29 Avr 2022
0 can either take run of positives or run of negatives, In fact I am trying to create based on the negative sign.

Connectez-vous pour commenter.

Réponse acceptée

Matt J
Matt J le 29 Avr 2022
Modifié(e) : Matt J le 29 Avr 2022
Download these files,
and then do like in the following:
A = [0 1 2 3 2 1 0 -1 -2 -2 -1 0 1 1.6 1.8 2 1 0];
G=groupConsec(A>=0);
output=groupFcn(@(x) {x}, A ,G); %return the groups as cell array elements,
%not separate variables
>> output{:}
ans =
0 1 2 3 2 1 0
ans =
-1 -2 -2 -1
ans =
0 1.0000 1.6000 1.8000 2.0000 1.0000 0

Plus de réponses (0)

Catégories

En savoir plus sur Startup and Shutdown dans Help Center et File Exchange

Tags

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by