필터 지우기
필터 지우기

How to organize a new matrix like matrix B ?

조회 수: 2 (최근 30일)
Pradya Panyainkaew
Pradya Panyainkaew 2018년 1월 19일
댓글: Pradya Panyainkaew 2018년 1월 20일
If I have matrix A that contains 4 columns. like this
A = [7210 01/12/2016 00:15:00 0 0.5502;
7210 01/12/2016 00:15:00 2 0.4903;
7210 01/12/2016 00:30:00 0 0.5487;
7210 01/12/2016 00:30:00 2 0.4914 ]
First column is a customer id and second column contains date time data.
I try to construct output matrix B to get the result follow this example
B = [7210 01/12/2016 00:15:00 0.5502 0.4903;
7210 01/12/2016 00:30:00 0.5487 0.4914]
How can create program to get a result like matrix B ?
Thanks in advance.

답변 (2개)

Matt J
Matt J 2018년 1월 19일
편집: Matt J 2018년 1월 19일
  댓글 수: 1
Pradya Panyainkaew
Pradya Panyainkaew 2018년 1월 19일
Sorry Matt J .
I think it is my fault to explain my point deeply. The last 2 columns of result (Matrix B) show the value of flag "0" and flag "2" (column 3 of A) in each interval. However, your code create only a value of flag "2". How can I modify it to get my result ?

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


Akira Agata
Akira Agata 2018년 1월 20일
Assuming your data A is stored in table format, I believe one possible solution would be like this.
% Your data stored in table format
ID = [7210; 7210; 7210; 7210];
Time = [...
datetime('01/12/2016 00:15:00','InputFormat','dd/MM/yyyy HH:mm:ss');...
datetime('01/12/2016 00:15:00','InputFormat','dd/MM/yyyy HH:mm:ss');...
datetime('01/12/2016 00:30:00','InputFormat','dd/MM/yyyy HH:mm:ss');...
datetime('01/12/2016 00:30:00','InputFormat','dd/MM/yyyy HH:mm:ss')];
Flag = [0;2;0;2];
Value = [0.5502;0.4903;0.5487;0.4914];
A = table(ID,Time,Flag,Value);
% Create the result B
A1 = A(A.Flag == 0,{'ID','Time','Value'});
A2 = A(A.Flag == 2,{'ID','Time','Value'});
B = innerjoin(A1,A2,'Keys',{'ID','Time'});
  댓글 수: 3
Akira Agata
Akira Agata 2018년 1월 20일
What is your MATLAB version? At least on the latest one (R2017b), this code works.
Pradya Panyainkaew
Pradya Panyainkaew 2018년 1월 20일
Thanks sir. I got 2017a

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

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by