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!