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

1 visualizzazione (ultimi 30 giorni)
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 Commenti
vimal r
vimal r il 24 Feb 2020
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 il 24 Feb 2020
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}.

Accedi per commentare.

Risposte (0)

Categorie

Scopri di più su Loops and Conditional Statements in Help Center e File Exchange

Prodotti


Release

R2016a

Community Treasure Hunt

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

Start Hunting!

Translated by