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 个评论
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 Center 和 File Exchange 中查找有关 Loops and Conditional Statements 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!