From: Florian on 3 Feb 2010 05:44 given a Matrix(n,m) i need to delete certain rows (or columns) defined by a vector example: M=magic(4) M=[16 2 3 13 5 11 10 8 9 7 6 12 4 14 15 1] F=[1 0 0 1]; %delete column 1 and 4 -> should result in M=[2 3 11 10 7 6 14 15] i wrote a function: function t=TrimMatrix(M,V) j=0; if size(V,1)==1 for i=1:size(V,2) if V(1,i)==1 M(:,i-j)=[]; j=j+1; end end else for i=1:size(V,1) if V(i,1)==1 M(i-j,:)=[]; j=j+1; end end end t=M; do you have any better solutions? is there any way not to use iterations?
|
Pages: 1 Prev: using workspace data in simulink block Next: Exit from a loop using push button |