Matrix Calculation - Calculating C in terms of A, based on a value of B
2 views (last 30 days)
Show older comments
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
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
Answers (0)
See Also
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!