How to apply element wise operation in three matrices

I have three matrices A, B, C (10 * 600 each). I want to learn to apply an operation (A[i][j] - C[i][j])/(B[i][j] - C[i][j]) on each element and store it in another matrix D. I'm new to this stuff. Any insights would be helpful.

Answers (1)

That is covered in the 2nd chapter of the Getting started guide (under matrix and array):
D = (A - C) ./ (B - C);
I would recommend that you go through all the chapters. This is really basic matlab usage.

3 Comments

Thank you for a quick reply. I've been using this method for the whole time. I'm loading the data from two mat files. I get this error "Reference to non-existent field 'Z' "
P = load('new1.mat');
Q = load('new2.mat');
R = load('new3.mat');
A = P.X;
B = Q.Y;
C = R.Z;
D = (A - C)./(B-C);
The mat file new3.mat does not contain a field Z. If field Z does not exist, then of course you cannot access it. Perhaps the fieldname is lowercase?
So, the actual question has nothing to do at all with what was asked! "I have three matrices A, B, C. I want to learn to apply an operation ...". Turns out that you don't have C and the problem is completely unrelated to how to calculate D.
As Stephen said, your error is due to the fact that new3.mat obviously does not have a Z variable. It's not something we can do anything about. Use a mat file that does have a Z variable or use the name of a variable that is actually in new3.mat

Sign in to comment.

Asked:

on 15 Jun 2018

Commented:

on 15 Jun 2018

Community Treasure Hunt

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

Start Hunting!