Division of two Multidimensional array

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 件のコメント

Image Analyst
Image Analyst 2021 年 7 月 11 日
That should work. Please post your arrays and tell us, for some particular location, what you're getting and what you thought you should get.
save('answers.mat', 'A', 'B');
mukesh bisht
mukesh bisht 2021 年 7 月 11 日
Please see the attached file
Here the results is represented by variable C = A./B
Image Analyst
Image Analyst 2021 年 7 月 11 日
Uh, ok, but I'm still waiting for you to answer "tell us, for some particular location, what you're getting and what you thought you should get."
Like C(1,3,5) is 150 when it should be
I'll check back later.
load('matlab.mat')
C = A ./ B;
numSlices = size(C, 3);
for k = 1 : numSlices
subplot(1, 3, 1);
imshow(A(:, :, k), [], 'InitialMagnification', 1000);
axis('on', 'image');
impixelinfo;
title('A', 'FontSize', 20);
subplot(1, 3, 2);
imshow(B(:, :, k), [], 'InitialMagnification', 1000);
axis('on', 'image');
impixelinfo;
title('B', 'FontSize', 20);
subplot(1, 3, 3);
imshow(C(:, :, k), [], 'InitialMagnification', 1000);
axis('on', 'image');
impixelinfo;
title('C', 'FontSize', 20);
drawnow;
pause(0.4);
end
mukesh bisht
mukesh bisht 2021 年 7 月 11 日
Like C(7,1,1). The actual answer should be NAN (C = 0/0) but it shows 0.0458
Image Analyst
Image Analyst 2021 年 7 月 11 日
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
mukesh bisht 2021 年 7 月 11 日
Sorry. Now I got it. Actually in Matlab workspace A(7,1,1) shows 0.000. So, this created confusion

サインインしてコメントする。

回答 (1 件)

LO
LO 2021 年 7 月 11 日
編集済み: LO 2021 年 7 月 11 日

0 投票

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

カテゴリ

ヘルプ センター および File ExchangeImages についてさらに検索

質問済み:

2021 年 7 月 11 日

コメント済み:

2021 年 7 月 11 日

Community Treasure Hunt

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

Start Hunting!

Translated by