Create a matrix from another one with an history window of 3 columns

조회 수: 1 (최근 30일)
Julien Benistant
Julien Benistant 2020년 1월 10일
댓글: Julien Benistant 2020년 1월 13일
Could someone help me with my problem.
I've got an original 2 by 25 matrix and I want to create a new 2 by 25 matrix with the same columns than the original one. But I want them reorganized such that a given column (:,n) in the new matrix is different from the columns (:,n:n+2) of the original matrix.
I've struggled to do that as Ifind a way using loops that need a lot of if statement to control for special cases... Is there someone with a simple(r) method to do that?
  댓글 수: 4
Stephane Dauvillier
Stephane Dauvillier 2020년 1월 13일
OK? sorry I don't know what you mean
Julien Benistant
Julien Benistant 2020년 1월 13일
Sorry I wasn't clear but I found a simple solution, I post it here in case of someone need help:
A= [1,3,5,7,8];
B = [4,12,20,28,32];
C = combvec(A,B);
S = randi([4 21],1);
V = [C(:,S:end), C(:,1:S-1)];
Basically I've just created a new matrix (V) randomly lagged (S) compared to the original one (C) !
Best,

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

답변 (1개)

Stephane Dauvillier
Stephane Dauvillier 2020년 1월 10일
You can try the function diff:
A = magic(5);
B = diff(A,[],2)
But B will have n-1 column what do you want for the extra column ?

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

제품


릴리스

R2015b

Community Treasure Hunt

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

Start Hunting!

Translated by