Comparing matrices and filling in the gaps

1 visualización (últimos 30 días)
Sam Fortescue
Sam Fortescue el 23 de Oct. de 2020
Respondida: Peter Perkins el 20 de Nov. de 2020
So,
I've got two matrices
a = [A;B;C;D;E;F]; %% The entire list of variables
b = [B;D;F, 5;13;6]; %% A set of data with missing variables and amounts of occurances in second coulmn
How can i get something that gives me something like this...
c = [A;B;C;D;E;F, 0;5;0;16;0;6]
  7 comentarios
Sam Fortescue
Sam Fortescue el 23 de Oct. de 2020
it is just a table of strings:
a = {'Brisbane City'; 'Kelvin Grove', 'Fortitude Valley'}
Rik
Rik el 23 de Oct. de 2020
Editada: Rik el 23 de Oct. de 2020
That is not a table of strings, but a cell array of char arrays. These specifics matter. It also isn't valid Matlab syntax, as you have only 1 char array on the first line, and two on the second line.
Please provide correct examples for a and b. We will probably be able to help your create something. The ismember function or the containers.Map data type might be what you're looking for.

Iniciar sesión para comentar.

Respuestas (1)

Peter Perkins
Peter Perkins el 20 de Nov. de 2020
There are just so many things you can do with joins:
>> a = table(["A";"B";"C";"D";"E";"F"]);
>> b = table(["B";"D";"F"], [5;13;6]);
>> outerjoin(a,b,'Key','Var1','Type','left','RightVariables','Var2')
ans =
6×2 table
Var1 Var2
____ ____
"A" NaN
"B" 5
"C" NaN
"D" 13
"E" NaN
"F" 6

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by