"lvn" wrote in message <kkj0nk$nc8$1@newscl01ah.mathworks.com>...
> Not a huge change, but this will be faster as it avoid resizing the matrix in every loop.
> Also avoids repetitive calls to size and ones.
>
> toremove=false(N,1);
> for R=1:N; %Selects row of matrix
> WF=Phases_Final(R,:);
> TF=WF(WF~=0); %Produces array of non zero terms in row
>
> for X=(R+1):N; %Compares above row to all rows below in the sorted matrix
> toremove(X)=all(ismember(TF,Phases_Final(X,:)));
> end
> end
> Phases_Final(toremove,:)=[];
>
>
>
> "Jono" wrote in message <kkf694$ddd$1@newscl01ah.mathworks.com>...
> > I'm after a way of cancelling "non minimal" rows of a matrix which contain all the non zero terms of a previous row plus more.
> >
> > For example
> > a=[ 1, 2, 0;
> > 3, 4, 5;
> > 1, 2, 6]
> >
> > Row 3 of 'a' should be cancelled as a row containing only the values 1 and 2 exists above it.
> >
> > My current coding uses a for loop to compare each row to every other row using an 'ismember' or all the non zero terms in that row. Any other row that returns a true is member statement is deleted. However the final problem has the potential to have over a million rows meaning this for loop takes an unfeasible amount of time to run.
> >
> > Does anyone have any ideas on how to speed this process up or take a different approach?
> >
> > Once sorted into ascending order of number of non zero terms my current coding is:
> >
> > for R=1:N; %Selects row of matrix
> > WF=Phases_Final(R,:);
> > TF=WF(WF~=0); %Produces array of non zero terms in row
> >
> > for X=(R+1):N; %Compares above row to all rows below in the sorted matrix
> > if ismember([TF(1,:)],Phases_Final(X,:))==[(ones(1,size(TF,2)))];
> > Phases_Final(X,:)=[];
> > else
> > end
> > end
> > end
> > .
> >
> > Any help is appreciated.
> >
> > Regards,
> >
> > Jon
Thanks for the help. Whilst this has sped the code up slightly it's still unfeasible for some of the larger problems I have to tackle. One is stretching into 6 million different system failure combinations...... Comparing every row to every row is just too much!
Regards,
Jon
