Hungarian Algorithm! Removing rows and comluns from matrix
显示 更早的评论
Hi I don't have much experience with Matlab and I'm doing this project for school, the task is for implement the Hungarian Algorithm. I'm almost at the end but now I'm having problems with removing rows and columns. I'll put my code and an example to show, if someone could help me I would appreciate it.
Let's say I have this matrix A: 15 0 0 0; 0 50 20 25; 35 5 0 10; 0 65 50 65;
(bare in mind that ca has the positions of the columns to erase and la the positions for the rows to erase)
ca=[1 3]
la=[1]
for j=1:length(ca)
A5=A3;
y=0:n;
A5(:,ca(j)-y(j))=[];
for i=1:length(la)
A5(la(i)-y(i),:)=[];
end
end
What I noticed is that if I don't use the 'y' after the first loop (for j=1) it erases the right column but them the A5 matriz turns 4x3 and the third original column is now the second, so the loop ends up deleting the first and fourth rows. I tried adding y for making the second loop decrease in one value so the third column is now the second, but instead it returns
0 20 25
35 0 10
0 50 65
I can't see what is wrong. Can someone help me please?
采纳的回答
更多回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Matrix Indexing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!