Delete and merge rows and columns based on values of other matrix under looop

1 次查看(过去 30 天)
i have a matrix of A and B1 B2 B3....Bn condition is to check B1 if zero then eliminate the rows and columns in matrix A store as A1 then it should go to B2 check and store in A2 till An.
A is nxn matrix
B1 B2.....Bn is a 1xn
Example:
if any of the element in B1 matrix is zero suppose element 3 it should eliminate 3rd row and 3rd column of Matrix A and store as A1
and it has to loop till Bn and store An matrices.
  5 个评论
vimal r
vimal r 2020-2-24
i have to store An matrix loop should end n variable output of A1 ....An based on the condition of Bnxn each row as one senario...
my input is Anxn and Bnxn
take first row of B check zeros and based on that it should eliminate rows and columns in matrix A and store as A1
then go to second row of B check and based on zero eliminate rows and columns in matrix A and store as A2
so on.....
Turlough Hughes
Turlough Hughes 2020-2-24
The code I provided above does what you ask with the exception of working through columns of B as opposed to rows of B because I did not have enough info at the time... that's is a simple fix. Having variables numbered A1 to An is a sign that you are doing something wrong because you either have to copy and paste code or use the eval function to generate these variables.
The results in the example I provided above are stored in a cell array which is in my opinion the easiest alternative to generating n variables. The results are then equivalently stored as
An{1,1}, An{1,2} all the way up to An{1,n}.

请先登录,再进行评论。

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Loops and Conditional Statements 的更多信息

产品


版本

R2016a

Community Treasure Hunt

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

Start Hunting!

Translated by