MATLAB swapping rows with zero in its pivot position, partial pivoting? -


i want matrix turn into

a =       1     2    -1     4     5      1    -6     7     5     6      0     0     4     7     5      0    -3     4     7     7      1     5     1     5     6 

this kind of matrix.

a =       1     2    -1     4     5      1    -6     7     5     6      1     5     1     5     6      0    -3     4     7     7      0     0     4     7     5 

so, row 0 in pivot position should go down.

i able find rows 0 in pivots using following code:

count=0; i=1:n     j=1:n         if a(i,j)~=0             break         else             count=count+1;             row(count)=i;             break         end     end end row  >> row =      3     4 

but don't know how can proceed after point. want make code applies kind of matrix. plz help.

i think need:

a =[1     2    -1     4     5;     1    -6     7     5     6;     0     0     4     7     5;     0    -3     4     7     7;     1     5     1     5     6]; % find last 0 in each row [val,lastzeroidx] = min(a == 0,[],2); % find rows first column 0 c = a(:,1) == 0; % eliminate rows first column isn't 0 lastzeroidx(~c) = 0; % sort location of last zeros [~,rowsidx] = sort(lastzeroidx,'ascend'); % rearrange b = a(rowsidx,:) 

and get:

b = [1     2    -1     4     5      1    -6     7     5     6      1     5     1     5     6      0    -3     4     7     7      0     0     4     7     5] 

Comments

Popular posts from this blog

javascript - Confirm a form & display message if form is valid with JQuery -

Retrieving ETA (estimated time of arrival) with Google Distance Matrix API and public transit as transport mode -

ionic framework - Meteor - Error: Failed to execute 'insertBefore' on 'Node' -