Multiplications inside a cell array
11 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Ishita Trivedi
il 23 Gen 2019
Commentato: Guillaume
il 23 Gen 2019

Hi everyone,
The above 4x12 is a cell array. Each cell contains numbers. What I want to do next is matrix multiplication between all elements of row 2 with row 4. So, (1,2)*(4,2). This will give a 33by33 matrix. Next, I want to store it in a new variable. But since this is a cell structure I am not able to do it and need help.
How can I concatenate it? Or should i convert the cell array to something else to make my life easier?
Thank you for your help.
0 Commenti
Risposta accettata
Kevin Phung
il 23 Gen 2019
use cell brackets to access contents of the cell array.
so if c is your 4x12 cell array, then c{2,1} would retun the array inside instead of the cell.
0 Commenti
Più risposte (1)
Guillaume
il 23 Gen 2019
Modificato: Guillaume
il 23 Gen 2019
result = cellfun(@times, yourcellarray(1, :), yourcellarray(4, :), 'UniformOutput', true)
will create a 1x12 cell array of 33x33 matrices. The same implemented as a loop:
result = cell(1, size(yourcellarray, 2));
for idx = 1:size(yourcellarray, 2)
result{idx} = yourcellarray{1, idx} .* yourcellarray{4, idx};
end
If you want a 33x33x12 matrix after that:
m = cat(3, result{:})
edit: got the wrong rows
edit again: and messed up the 'UniformOutput'
4 Commenti
Vedere anche
Categorie
Scopri di più su Cell Arrays in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!