フィルターのクリア

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 Center および File ExchangeLogical についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by