Clear Filters
Clear Filters

Create an array containing the values of a cell type matrix corresponding to each of the examples contained in other cell type matrix.

2 views (last 30 days)
I have a data matrix 17000x4 cell type and other cell matrix type 49000x38 containing both text and numerical data . The first column of the second matrix contains 49000 numerical labels elements while the first column of the first array contains 17000 examples of some of these labels . My goal is to create an array containing the values of the columns 2:38 the second matrix corresponding to each of the examples 17000 . In short , I want to look for each example corresponding feature vector contained in the second matrix.
I want to do somthing like this but using vectors instead single values for each key: http://es.mathworks.com/help/matlab/matlab_prog/creating-a-map-object.html#brq_zd0-1

Accepted Answer

Guillaume
Guillaume on 19 May 2016
Edited: Guillaume on 19 May 2016
The code you've posted is equivalent to:
[numA, ~, A] = xlsread('Data.xlsx',1);
[numB, ~, B] = xlsread('Data.xlsx',2);
[found, rows] = ismember(numA(:, 1), numB(:, 1));
%option that keeps rows of A not found in B:
out = [A, cell(size(A, 1), size(B, 2)-1)];
out(found, size(A, 2)+1:end) = B(rows, 2:end)
%option that discard rows of A not found in B (simpler)
out = [A(found, :), B(rows, 2:end)]
except this is more robust since it'll work even if a key is duplicated.

More Answers (0)

Categories

Find more on Numeric Types in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!