Comparing matrices of different dimensions

8 views (last 30 days)
mathman
mathman on 16 Dec 2017
Answered: Image Analyst on 16 Dec 2017
I have 3 matrices, one is a 1x301 array,A, one is a scalar value,B, and the 3rd is 10x10x10 array,C. I need to be able to do: A-B/C.
I've tried it using meshgrid by doing: [An, Bn, Cn] = meshgrid(A,B,C) following it up by F = An - (Bn ./ Cn); so that a matrix can be output containing the values of the sum for each element.
I'm unsure whether this is the right method or the best way to go about it
  2 Comments
Image Analyst
Image Analyst on 16 Dec 2017
I'm not sure what you want to do. A has 301 values while C has a thousand values. In what way do you want to combine them? For example, what is the last element of F? The 301st? The 1000th? What elements of A and C would go into making up the last value of F? Please spell it out explicitly.
mathman
mathman on 16 Dec 2017
I want to calculate A-(B/C) for each element of each matrix and output the results of that calculation into another matrix, F.
For example:
A = [8 9 10]
B = [28 45 48]
C = [14 15 16]
F = [6 6 7]
Something like that. The problem I'm having is making it so matrices of different dimensions can be compared.
The last element of F should be the 301st value.

Sign in to comment.

Answers (1)

Image Analyst
Image Analyst on 16 Dec 2017
So what do you plan on doing with elements 302 - 1000 of C? Ignore them? And in what order do you plan on taking the first 301 elements of C?
lastElement = max([numel(A), numel(B), numel(C)]);
F = A(1:lastElement) - (B(1:lastElement) ./ C(1:lastElement));
this takes c in column major order.

Categories

Find more on Deep Learning Toolbox 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!