Divide a matrix with an array along a specific dimension
Ältere Kommentare anzeigen
A=rand(10,20,30);
B=[1:30];
I want to divide A with B along the third dimension. I got the required result using loop.
for ii=1:30
C(:,:,ii)=A(:,:,ii)/B(ii);
end
But is there any pre-defined function which does the same operation, which takes the dimension as a input along which we want to divide a matrix.
Akzeptierte Antwort
Weitere Antworten (1)
Akira Agata
am 16 Mär. 2018
How about using arrayfun ?
C = arrayfun(@(k) A(:,:,k)./B(k), 1:30,'UniformOutput',false);
C = cat(3,C{:});
1 Kommentar
Beata Opacka
am 26 Mär. 2020
This works amazing!!!
Kategorien
Mehr zu Matrix Indexing finden Sie in Hilfe-Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!