필터 지우기
필터 지우기

I want to find different values in different matrices at the same date???

조회 수: 2 (최근 30일)
Dear all, I have again a problem with the date. I have two different matrices with different dimensions. In the matrix jump is in the fist column the date, but the different points in time are not equally spaced. So some days between the years 2004 and 2012 are missing. In the second column are the values of the the jumps. The dimension of the matrix is 2746*2. The second matrix has the dimension 3288*4. So this matrix has also the date in the first column but much more points in time. I want to add the values of the first matrix to the second matrix and the values in the first matrix should be at the same day in the second matrix as before. So the date is the selection criterion. The date is converted to numbers. I tried it with an if else loop but I did not work. How can I add the values of jump to the second matrix??? Thank you in advance.
  댓글 수: 3
Azzi Abdelmalek
Azzi Abdelmalek 2013년 2월 20일
편집: Azzi Abdelmalek 2013년 2월 20일
What do you mean by to add a value? is it a sum or what? In the second matrix there are 3 columns while in the first there is one, where to add these values?
Thor
Thor 2013년 2월 20일
The date is a number, because I converted it with the command datenum. In the matix jump was it dd-mmm-yyyy hh:mm:ss and in the other matrix only dd-mmm-yyyy. I want to separate the second column of jump and add each value to second matrix to the same date, where it was before. So I can not use horzcat because there are different dimensions of time. Each point of time in jump is in the second matrix but in a different adjustment. So I dont want to sum up and I want to create a 5th column in the second matrix. I want to reallocate 2746 values to the second matrix and the other values in the new 5th column should be zero. Thank you!

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

채택된 답변

Thorsten
Thorsten 2013년 2월 20일
A = [1 3; 2 4; 5 8];
B = [[1:5]' [ 40 50 60 70 80]'];
for i = 1:size(A, 1)
B(find(A(i,1)== B(:,1)), 3) = A(i, 2);
end
  댓글 수: 4
Thorsten
Thorsten 2013년 2월 20일
You have to convert the dates to numbers and everything should work.
Thor
Thor 2013년 2월 20일
Yes you're right. I had to round the datevector, because of the different format with additional hh:mm:ss. So now it works. Thank you!

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Dates and Time에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by