Combining arrays with different dimensions
3 ビュー (過去 30 日間)
古いコメントを表示
how do i combine multiple arrays with different dimensions into a single one
For example:
array_1 = [1.1, 1.25, 1.3, 1.5, 1.6, 1.9, 1.99; 100, 120, 50, 78, 12, 15, 22]
array_2 = [1.09, 1.12, 1.21, 1.46, 1.58, 1.6, 1.89, 1.95, 1.99; 10, 130, 20, 12, 77, 34, 5, 22, 97]
The first row for each array can be seen as x values and seccond row will be y values, therefore the code should produce the following data
combined = [1.09, 1.1, 1.12, 1.21, 1.25, 1.3, 1.46, 1.5, 1.58, 1.6, 1.89, 1.9, 1.95, 1.99; 0, 100, 0, 0, 120, 50, 0, 78, 0, 12, 0, 15, 0, 22; 10, 0, 130, 20, 0, 0, 12, 0, 77, 34, 5, 0, 22, 92]
1 件のコメント
Torsten
2022 年 3 月 31 日
The rule how you combine the two matrices (i.e. the indices when you take one and when you take two entries one after the other from array_2) is not clear to me.
回答 (1 件)
MJFcoNaN
2022 年 4 月 4 日
I guess the last "92" is a typo.
x1 = array_1(1, :);
x2 = array_2(1, :);
y1 = array_1(2, :);
y2 = array_2(2, :);
x = unique([x1, x2]);
y = zeros(2, length(x));
[~, locb1] = ismember(x1, x);
[~, locb2] = ismember(x2, x);
y(1, locb1) = y1;
y(2, locb2) = y2;
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Matrices and Arrays についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!