for loop with a spread

조회 수: 9 (최근 30일)
Matthew Worker
Matthew Worker 2020년 6월 10일
편집: N/A 2021년 1월 24일
Hi guys,
I wanted to get an idea on how I should approach a problem. Say for example I have a 100x48 matrix and I want to get a new matrix that takes the 48th value substracts it by the 39th value and so on. So next would be the 47th value subtracted by the 38th value and for this to continue all the way until I reach the 1st value. This would be done for all rows. I believe at the end I would end up with a matrix of 100x39.
Any help would be truly appreciated it.

채택된 답변

darova
darova 2020년 6월 11일
use for loop
[m,n] = size(A); % your matrix
A1 = zeros(m,n-9); % new matrix preallocation
for i = 1:n-9
A1(:,i) = A(:,n-i+1)-A(:,n-i-8);
end
  댓글 수: 2
N/A
N/A 2020년 6월 11일
Thank you for your answer. It's extremly helpful.
darova
darova 2020년 6월 12일
my plesure

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

추가 답변 (0개)

카테고리

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