Comparing matrices and filling in the gaps

1 visualizzazione (ultimi 30 giorni)
Sam Fortescue
Sam Fortescue il 23 Ott 2020
Risposto: Peter Perkins il 20 Nov 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 Commenti
Sam Fortescue
Sam Fortescue il 23 Ott 2020
it is just a table of strings:
a = {'Brisbane City'; 'Kelvin Grove', 'Fortitude Valley'}
Rik
Rik il 23 Ott 2020
Modificato: Rik il 23 Ott 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.

Accedi per commentare.

Risposte (1)

Peter Perkins
Peter Perkins il 20 Nov 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

Prodotti

Community Treasure Hunt

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

Start Hunting!

Translated by