How do I create such matrix ? (please look at the thread for further details)
1 次查看(过去 30 天)
显示 更早的评论
Hi,
Let say I have a matrix of m column. eg[X1 X2 X3 X4 ... Xm].
How do I create a matrix that becomes [X1 X2-X1 X3-X2 X4-X3 ... Xm-Xm-1]for m columns ?
And if I have n rows and m column, how do I create such matrix?
0 个评论
回答(2 个)
Azzi Abdelmalek
2013-12-24
编辑:Azzi Abdelmalek
2013-12-24
v=[10 50 200 1000]
out=[v(1) diff(v)]
1 个评论
Azzi Abdelmalek
2013-12-24
v=[10 50 200 1000;1 5 20 100]
out=[v(:,1) diff(v,[],2)]
Image Analyst
2013-12-24
Alternative ways that could be extended for subtracting more than 2 columns, but Azzi's method is probably better/simpler/easier to understand for subtracting just 2 columns.
outc = [v(1), conv(v, [1,-1], 'valid')] % 1D
outc2 = [v(:,1), conv2(v, [1,-1], 'valid')] % 2D
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Logical 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!