Element by element (xor) operation on cells.
Mostrar comentarios más antiguos
I have two variables, Test and Train.
Test = cell of dimension 10 x 1 and
Train = cell of dimension 20 x 1
All elements are logical.
I want an operation similar to matrix multiplication, except that I want xor, instead of multiplication.
All of the 100 elements in Test should be xor(ed) with each of the 2000 elements in Train. All the while, I was doing this using for loop, but I want to avoid for loops now. I was trying to figure out performing this using bsxfun, but couldn't get it as desired. What is the most efficient way to do this?
5 comentarios
Walter Roberson
el 1 de Ag. de 2017
Are you saying that Test is a cell array in which each element is a single scalar logical value? If so then why are you storing the values in a cell array instead of a vector?
Could you confirm that the output you want is 100 x 2000?
James Tursa
el 1 de Ag. de 2017
Editada: James Tursa
el 1 de Ag. de 2017
Please show a small example of inputs and desired output. E.g., in a regular matrix multiply,
c11 = a11*b11 + a12*b21 + a13*b31 + ...
What would be the equivalent "xor matrix multiply" operation that you want?
c11 = xor(a11,b11) or xor(a12,b21) or xor(a13,b31) or ...
Or something else perhaps using "and"?
Or will this be more like an outer product as Walter suggests?
Meghana Dinesh
el 2 de Ag. de 2017
James Tursa
el 2 de Ag. de 2017
Loops is probably the way to go here. You could potentially pull things out via cell2mat, do the calculations, and then use cell2mat to get your result, but why bother with all of that data copying? Using loops is straightforward and easy to read.
Meghana Dinesh
el 2 de Ag. de 2017
Respuestas (1)
Akira Agata
el 2 de Ag. de 2017
I think cellfun would be suitable to this, like:
load('Train&Test.mat');
Result = cell(numel(Test), numel(Train));
for kk = 1:numel(Train)
Result(:,kk) = cellfun(@xor, repmat(Train(kk),numel(Test),1), Test,...
'UniformOutput', false);
end
Categorías
Más información sobre Matrix Indexing en Centro de ayuda y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!