Borrar filtros
Borrar filtros

Combining arrays with different dimensions

5 visualizaciones (últimos 30 días)
Ruhul Islam
Ruhul Islam el 31 de Mzo. de 2022
Respondida: MJFcoNaN el 4 de Abr. de 2022
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 comentario
Torsten
Torsten el 31 de Mzo. de 2022
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.

Iniciar sesión para comentar.

Respuestas (1)

MJFcoNaN
MJFcoNaN el 4 de Abr. de 2022
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;

Categorías

Más información sobre Matrices and Arrays en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by