Referencing variables in an array
显示 更早的评论
Very novice MATLAB user. I have a matrix and a function that includes the rows to delete. How do I delete those rows referencing the function?
This is what I have:
x = find(final_allocation~= 0);
rowdrop = preferences(:,1) == [x];
preferences(rowdrop,:) = []
---
x = [1 2 4]
preferences =
2 7 9 6 5 4 1 3 8
4 6 1 9 5 3 2 7 8
4 2 6 7 9 5 3 8 1
1 5 2 3 9 4 7 8 6
3 8 6 9 2 4 1 7 5
7 8 1 2 4 6 3 9 5
2 4 3 1 8 9 7 6 5
5 1 2 9 4 7 8 3 6
6 1 8 5 2 9 4 7 3
I want to delete rows 1, 2, and 4 using variable x.
回答(1 个)
Fangjun Jiang
2019-2-25
If you want to remove the [1 2 4]th row of a matrix
x=[1 2 4];
a=magic(6);
a(x,:)=[];
类别
在 帮助中心 和 File Exchange 中查找有关 Matrices and Arrays 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!