i have a column matrix [23; 34;22;13]. i need to create set of column matrixs ,which give 1 and -1 in numbers if the next number is less than and larger than.

3 vues (au cours des 30 derniers jours)
A=[23; 34;22;13] output matrixs=[1;-1;-1],[-1,-1],[-1]

Réponse acceptée

Guillaume
Guillaume le 2 Oct 2016
One possibility:
A = [23; 34; 22; 13];
out = arrayfun(@(idx) sign(A(idx+1:end) - A(idx)), 1:numel(A)-1, 'UniformOutput', false)
celldisp(out)
  9 commentaires

Connectez-vous pour commenter.

Plus de réponses (1)

Atsushi Ueno
Atsushi Ueno le 2 Oct 2016
Modifié(e) : Atsushi Ueno le 3 Oct 2016
I have modified the last answer after getting your comment.
A = [23; 34; 22; 13];
B = sign(diff(A));
matrixs = {0};
for i = numel(B):-1:1
matrixs = {B(i:end), matrixs{:}};
end

Catégories

En savoir plus sur Resizing and Reshaping Matrices dans Help Center et File Exchange

Tags

Aucun tag saisi pour le moment.

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by