Matrix Calculation - Calculating C in terms of A, based on a value of B

2 views (last 30 days)
I am working on a code for my school project. I have 2 input matrices A and B. Based on a value of B, I want to calculate a C matrix which is a function of A alone.
For example, if B (i) >10, I want to calculate C(i) = x * A(i);
I have the input values for A and B as 6 separate matrices of different lengths. I cant find a way to merge them as a single matrix which could be later called for in the C matrix calculation.
Please help.
  3 Comments
Karthikumar Sambasivam
Karthikumar Sambasivam on 24 Nov 2020
Yes. At the end I want C to use specific values of A to calculate, based on specific values of B. I think that will anyway end up being a matrix?
Rohit Pappu
Rohit Pappu on 27 Nov 2020
As per my understanding of the question,you can iterate through the elements of B, and calculate the values of C based on if conditions
Example:
[m,n] = size(A);
C = zeros(m,n); %% Create a matrix C filled with zeros
for i=1:m
for j=1:n
if(B(i,j)>10)
C(i) = x*A(i)
end
end
end

Sign in to comment.

Answers (0)

Categories

Find more on Creating and Concatenating Matrices 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!