필터 지우기
필터 지우기

How can I merge my data set based on the time in MATLAB?

조회 수: 1 (최근 30일)
Tania Islam
Tania Islam 2021년 1월 25일
댓글: Tania Islam 2021년 1월 26일
I want to merge the two data into one. But as they are in two different times that's why I cannot just combine them.
I need to add them by keeping the time as it is. How can I do this?
data_1_y_axes=[0,1,3,5,4,6,8,9,7]
time_1_x_axes=[.02,0.03,.05,.06,.07,0.08,0.09,.1,.2]
data_2_y_axes=[0,2,4,5,2,7,5,7,5]
time_2_x_axes=[.002,0.004,.006,.009,.02,0.04,0.06,.07,.09]
plot(time_1_x_axes,data_1_y_axes)
hold on
plot(time_2_x_axes,data_2_y_axes)
My expected data will be as follows:
New_data=[ 0, 2,4,5,2+0,1,7,3,5+5,7+4,6,5+8,9,7]
New_time=[.002,.004,.006,.009,.02,.03,.04,.05,.06,.07,.08,.09,.1,.2]
How can I do this?

답변 (1개)

KSSV
KSSV 2021년 1월 25일
data_1_y_axes=[0,1,3,5,4,6,8,9,7] ;
time_1_x_axes=[.02,0.03,.05,.06,.07,0.08,0.09,.1,.2] ;
data_2_y_axes=[0,2,4,5,2,7,5,7,5] ;
time_2_x_axes=[.002,0.004,.006,.009,.02,0.04,0.06,.07,.09] ;
plot(time_1_x_axes,data_1_y_axes)
hold on
plot(time_2_x_axes,data_2_y_axes)
x = [time_1_x_axes time_2_x_axes] ;
y = [data_1_y_axes data_2_y_axes] ;
[x,idx] = sort(x) ;
y = y(idx) ;
plot(x,y)
  댓글 수: 1
Tania Islam
Tania Islam 2021년 1월 26일
data_1_y_axes = [0,1,3,5,4,6,8,9,7];
time_1_x_axes = [0.02,0.03,0.05,0.06,0.07,0.08,0.09,0.1,0.2];
data_2_y_axes = [0,2,4,5,2,7,5,7,5];
time_2_x_axes = [0.002,0.004,0.006,0.009,0.02,0.04,0.06,0.07,0.09];
Data_Vector = [data_1_y_axes data_2_y_axes];
Time_Vector = [time_1_x_axes time_2_x_axes];
Unique_Times = unique(Time_Vector);
for Sample_Index = 1: length(Unique_Times)
Time_Value = Unique_Times(Sample_Index);
Indices_With_Matching_Time = find(Time_Vector == Time_Value);
Output_Data(Sample_Index) = sum(Data_Vector(Indices_With_Matching_Time));
end
plot(Unique_Times,Output_Data);
Thank you for your help. This is answer for this question. I think it may help others also.

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

카테고리

Help CenterFile Exchange에서 Annotations에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by