필터 지우기
필터 지우기

How can i create a matrix with samples from irregular X,Y

조회 수: 1 (최근 30일)
Richard Perosa Fernandes
Richard Perosa Fernandes 2018년 4월 2일
댓글: Akira Agata 2018년 4월 3일
Example:
Am01= (x;y) = (1 2 3 4 5 ; 10 20 30 40 50)
Am02= (x;y) = (1 3 4 ; 30 20 50)
Am03= (x;y) = (1 2 5 ; 25 93 47)
Matrix Funded:
x - y1 - y2 - y3
1 10 30 25
2 20 0 93
3 30 20 0
4 40 0 0
5 50 50 47

채택된 답변

Akira Agata
Akira Agata 2018년 4월 3일
One possible solution would be like this:
Am01 = [1 2 3 4 5 ; 10 20 30 40 50]';
Am02 = [1 3 4 ; 30 20 50]';
Am03 = [1 2 5 ; 25 93 47]';
x = unique([Am01(:,1) ; Am02(:,1) ; Am03(:,1)]);
A = zeros(numel(x),4);
A(:,1) = x;
[~,loc] = ismember(Am01(:,1),A(:,1));
A(loc,2) = Am01(:,2);
[~,loc] = ismember(Am02(:,1),A(:,1));
A(loc,3) = Am02(:,2);
[~,loc] = ismember(Am03(:,1),A(:,1));
A(loc,4) = Am03(:,2);
The output is:
>> A
A =
1 10 30 25
2 20 0 93
3 30 20 0
4 40 50 0
5 50 0 47
  댓글 수: 1
Akira Agata
Akira Agata 2018년 4월 3일
+1
If your data is stored in table variables, you can use outerjoin function. Here is an example.
Am01 = [1 2 3 4 5 ; 10 20 30 40 50]';
Am02 = [1 3 4 ; 30 20 50]';
Am03 = [1 2 5 ; 25 93 47]';
T1 = array2table(Am01,'VariableNames',{'ID','Am01'});
T2 = array2table(Am02,'VariableNames',{'ID','Am02'});
T3 = array2table(Am03,'VariableNames',{'ID','Am03'});
T = outerjoin(T1,T2,'Keys','ID','MergeKeys',true);
T = outerjoin(T,T3, 'Keys','ID','MergeKeys',true);
T = fillmissing(T,'constant',0);
Result:
>> T
ans =
5×4 table
ID Am01 Am02 Am03
__ ____ ____ ____
1 10 30 25
2 20 0 93
3 30 20 0
4 40 50 0
5 50 0 47

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

추가 답변 (1개)

Richard Perosa Fernandes
Richard Perosa Fernandes 2018년 4월 3일
Thank you very much akira!

카테고리

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