# Division of two Multidimensional array

1 view (last 30 days)
mukesh bisht on 11 Jul 2021
Commented: mukesh bisht on 11 Jul 2021
Hi
I have two multidimensional array say A (30x10x30) & B(30x10x30). I want to divide the elements of A by the corresponding elements of B.
How to do it.
I am not getting corrrect result by diving like this A./B
##### 6 CommentsShow 4 older commentsHide 4 older comments
Image Analyst on 11 Jul 2021
OK, I get
load('matlab.mat')
C = A ./ B;
fprintf('A(7,1,1) = %f.\n', A(7,1,1));
fprintf('B(7,1,1) = %f.\n', B(7,1,1));
fprintf('C(7,1,1) = %f.\n', C(7,1,1));
A(7,1,1) = 0.000055.
B(7,1,1) = 0.001192.
C(7,1,1) = 0.045776.
Explain why you get 0 for A and B. Did you upload the wrong data?
mukesh bisht on 11 Jul 2021
Sorry. Now I got it. Actually in Matlab workspace A(7,1,1) shows 0.000. So, this created confusion

Sign in to comment.

### Answers (1)

LO on 11 Jul 2021
Edited: LO on 11 Jul 2021
you can iterate the 2D division
A = rand(30,10,30);
B = rand(30,10,30);
sz=size(A);
r = cell(sz(3),1);
for i = 1:sz(3)
r{i} = A(:,:,i)./B(:,:,i); % in this cell array you will have the divisions
end
##### 0 CommentsShow -2 older commentsHide -2 older comments

Sign in to comment.

### Categories

Find more on Loops and Conditional Statements 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!