필터 지우기
필터 지우기

Subtracting different sized arrays in intervals

조회 수: 1 (최근 30일)
Kai Hillers
Kai Hillers 2020년 5월 8일
댓글: Kai Hillers 2020년 5월 8일
Hello everyone,
i have a problem where i just cant wrap my head around: I have two arrays, one is a 2678400x1 double (call this A) and one is a 4464x1 double (call this B). I want to subtract the first element of B from the first 600 elements of A, then the second element of B from the 601 to 1200 elements of A without using a loop. The calculated array would look something like this:
C(1) = A(1) - B(1)
C(2) = A(2) - B(1)
C(3) = A(3) - B(1)
...
C(601) = A(601) - B(2)
...
C(1201) = A(1201) - B(3)
etc.
I am using MatLab R2015a

채택된 답변

Fangjun Jiang
Fangjun Jiang 2020년 5월 8일
A=(1:24)';
B=(1:6)';
C=A-repelem(B,numel(A)/numel(B))
  댓글 수: 1
Kai Hillers
Kai Hillers 2020년 5월 8일
Perfect, Fangjun Jiang. You are truly a MVP! :) I didnt know the function repelem() existed and couldn't find it, thanks for helping me out!

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

추가 답변 (0개)

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by