for loop with a spread

10 Ansichten (letzte 30 Tage)
Matthew Worker
Matthew Worker am 10 Jun. 2020
Bearbeitet: N/A am 24 Jan. 2021
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.

Akzeptierte Antwort

darova
darova am 11 Jun. 2020
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 Kommentare
N/A
N/A am 11 Jun. 2020
Thank you for your answer. It's extremly helpful.
darova
darova am 12 Jun. 2020
my plesure

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu MATLAB finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by