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.
1 view (last 30 days)
Show older comments
shashika iresh
on 2 Oct 2016
Commented: shashika iresh
on 4 Oct 2016
A=[23; 34;22;13] output matrixs=[1;-1;-1],[-1,-1],[-1]
0 Comments
Accepted Answer
More Answers (1)
Atsushi Ueno
on 2 Oct 2016
Edited: Atsushi Ueno
on 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
0 Comments
See Also
Categories
Find more on Resizing and Reshaping Matrices 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!