Comparing matrices and filling in the gaps

1 view (last 30 days)
Sam Fortescue
Sam Fortescue on 23 Oct 2020
Answered: Peter Perkins on 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 Comments
Sam Fortescue
Sam Fortescue on 23 Oct 2020
it is just a table of strings:
a = {'Brisbane City'; 'Kelvin Grove', 'Fortitude Valley'}
Rik
Rik on 23 Oct 2020
Edited: Rik on 23 Oct 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.

Sign in to comment.

Answers (1)

Peter Perkins
Peter Perkins on 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

Products

Community Treasure Hunt

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

Start Hunting!