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 次查看(过去 30 天)
显示 更早的评论
A=[23; 34;22;13] output matrixs=[1;-1;-1],[-1,-1],[-1]
0 个评论
采纳的回答
Guillaume
2016-10-2
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 个评论
更多回答(1 个)
Atsushi Ueno
2016-10-2
编辑:Atsushi Ueno
2016-10-3
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 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Resizing and Reshaping Matrices 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!