How to find the individual values that produces max results in the addition of two time series?

조회 수: 1 (최근 30일)
Hello All,
I have results in several time series. If I add the two time series then I want to find the two values from two time series which would give the maximum result and then insert those values in another matrix. For example
Case 1: A = (1; 0.5; 1. 5; 2); B = (0.5; 0.3; 1; 0.2) and the answer would be R = [1.5, 1]
and the process should continue for many more sets containing matrix A and C, A and D, A and E, etc.
Thanks

채택된 답변

Antoni Garcia-Herreros
Antoni Garcia-Herreros 2023년 5월 10일
Data=rand(4,10); % Each column of Data corresponds to B,C,D E F
Data(:,1)= [0.5; 0.3; 1; 0.2]; % First column corresponds to B
A = [1; 0.5; 1.5; 2];
R=zeros(2,size(Data,2)); %Matrix where your results will be stored
for j=1:size(Data,2)
[m,i]=max(A+Data(:,j)); % Find the maximum of the sum between A and the corresponding vector (B, C,D,...)
R(:,j)=[A(i);Data(i,j)];
end
R
R = 2×10
1.5000 2.0000 2.0000 2.0000 2.0000 2.0000 2.0000 2.0000 2.0000 2.0000 1.0000 0.9462 0.6854 0.3197 0.6258 0.3851 0.9645 0.1835 0.5872 0.2452

추가 답변 (0개)

카테고리

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

제품


릴리스

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by