how to Concatenate big string matrices of different sizes
2 ビュー (過去 30 日間)
古いコメントを表示
hello everyone, i have 4 big string matrices with different sizes(a=192320x17,o=221847x8,r=55768x25 and v=394402x17) and they have one same column(case number) i want to know how can i Concatenate or merge them together to get a matice(c=394402x64) by putting rows of a specific case number from each matric to one row in c matric and put NAN or ' ' for rows that dont have any matches
i tried for loop for this but it takes a long time about 2days!!
i want to know if anyone have a faster way for this
thank you
2 件のコメント
回答 (2 件)
Jan
2021 年 7 月 20 日
With some bold guessing:
% [UNTESTED] Please povide a small test data set
keyIndex = 1; % Guessing, that the "case number" is found in first column
keyList = union(union(union(a(:, keyIndex), o(:, keyIndex)), r(:, keyIndex)), v(:, keyIndex));
data = {a, o, r, v};
result = keyList;
for k = 1:4
aData = data{k};
[match, index] = ismember(keyList, aData(:, keyIndex));
result(match, end+1 : end+size(aData, 2) - 1) = aData(index, 2:end);
end
This would be easier with tables objects and outerjoin().
0 件のコメント
Star Strider
2021 年 7 月 20 日
I would read all of them in as table arrays using readtable, then use the innerjoin function to join the first two tables, then the other tables in a loop to the first innerjoin operation. Use the case number variable as the Keys variable.
The procedure would go something lilke this:
T{1} = readtable('FirstMatrix.txt');
...
T{4} = readtable('FourthMatrix.txt');
TJ = innerjoin(T{1},T{2},'Keys','CaseNr');
for k = 1:2
TJ = innerjoin(TJ,T{k+2},'Keys','CaseNr');
end
This is UNTESTED since the matrices are not provided (and I cannot be certain that this procedure would work with your matrices, in any event). Make appropriate changes to get the result you want. It will likely be necessary to experiment.
.
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Loops and Conditional Statements についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!