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

2 visualizaciones (últimos 30 días)
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 comentarios
Karthikumar Sambasivam
Karthikumar Sambasivam el 24 de Nov. de 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 el 27 de Nov. de 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

Iniciar sesión para comentar.

Respuestas (0)

Categorías

Más información sobre Multidimensional Arrays en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by