Matrix subtraction every two adjacent column

조회 수: 2 (최근 30일)
MUHAMMAD SYAKIR YUSRI
MUHAMMAD SYAKIR YUSRI 2021년 2월 12일
댓글: MUHAMMAD SYAKIR YUSRI 2021년 2월 12일
Hello everyone,I have a matrix x with MxN = (3750X666) and I want to subtract every two adjacent column,normalize it and create a new matrix y= [x(:,n)-x(:,1:n-1))] ./ x(;,n), n start with 2nd column and end with N, how can I do it?
  댓글 수: 4
Matt J
Matt J 2021년 2월 12일
Here is the solution you were given. As you can see, it does 664 subtractions, which is exactly the number of pairs available (separated by a stride of 2) along the whole width of your matrix.
x=rand(3750,666);
y=(x(:,3:end)-x(:,1:end-2))./x(:,2:end-1);
whos y
Name Size Bytes Class Attributes y 3750x664 19920000 double
MUHAMMAD SYAKIR YUSRI
MUHAMMAD SYAKIR YUSRI 2021년 2월 12일
Thank Matt, i was confused earlier. Thank you for the explanation.

댓글을 달려면 로그인하십시오.

답변 (2개)

Stephan
Stephan 2021년 2월 12일
% sample data
A = randi(10,5,3)
% second col minus first and so on
B = A(:,2:end) - A(:,1:end-1)
% first col minus second and so on
C = A(:,1:end-1) - A(:,2:end)

Matt J
Matt J 2021년 2월 12일
y=diff(x,1,2);

카테고리

Help CenterFile Exchange에서 MATLAB에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by