Element by element (xor) operation on cells.

3 vues (au cours des 30 derniers jours)
Meghana Dinesh
Meghana Dinesh le 1 Août 2017
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 commentaires
James Tursa
James Tursa le 2 Août 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
Meghana Dinesh le 2 Août 2017
Right, thanks!
Since MATLAB is used for matrix operations, I thought there would be a more efficient way to perform this task. In reality, the dimensions are in the range of 27,000 so it takes a lot of time to compute the output.

Connectez-vous pour commenter.

Réponses (1)

Akira Agata
Akira Agata le 2 Août 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

Catégories

En savoir plus sur Matrix Indexing dans Help Center et File Exchange

Tags

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by