function RETURN=colop(matrix,user) global undo; %this allows for undoing of previous command if global undo is declared in calling environment. global noprint global err noprint=0; err=0; if(exist('matrix')==0) %check if passed matrix is defined noprint=1; sprintf('%s\n','The matrix you have passed as an argument to COLOP has not been defined.') error(' ') end undo=matrix; sizecheck=size(matrix); check_for_r=findstr(user,'r'); if (isempty(check_for_r)==0) sprintf('%s','When using COLOP you must use [c] in the command line instead of [r] (which you use with the function ROWOP)') error(' ') end a = sscanf(user,' c%d = c%d %[+-] c%d'); %note: this also used for sign_coeff if (size(a)==[4,1]) %no multiplier or brackets q = sscanf(user,' c%d = c%d %[+-] c%d'); operand=q(1,1); multiplier=1; multiplee=q(4,1); check=q(2,1); else %there exists multiplier and possibly brackets, division operator brackets=findstr(user, '(' ); %check for bracket m=findstr(user,'/'); %check for fractional multiplier if (isempty(m)==1) % case there is no division operator in string if (isempty(brackets)==1) %case no brackets no division operator nobracknodiv=sscanf(user,' c%d = c%d %[+-] %f c%d'); operand=nobracknodiv(1,1); multiplier=nobracknodiv(4,1); multiplee=nobracknodiv(5,1); check=nobracknodiv(2,1); else %case have brackets but no division operator bracknodiv=sscanf(user,' c%d = c%d %[+-] ( %f ) c%d'); operand=bracknodiv(1,1); multiplier=bracknodiv(4,1); multiplee=bracknodiv(5,1); check=bracknodiv(2,1); end else % case there is a division operator: scan string accordingly if (isempty(brackets)==1) %case no brackets and have division operator b=sscanf(user,' c%d = c%d %[+-]%f / %f c%d'); operand=b(1,1); multiplier=b(4,1)/b(5,1); multiplee=b(6,1); check=b(2,1); else %case have brackets and have division operator brackplusdiv=sscanf(user,' c%d = c%d %[+-]( %f / %f) c%d'); operand=brackplusdiv(1,1); multiplier=brackplusdiv(4,1)/brackplusdiv(5,1); multiplee=brackplusdiv(6,1); check=brackplusdiv(2,1); end end end % consistency and size checks mistake_true=0; if(operand>sizecheck(1,2)) sprintf('%s\n%s','Error: The index number of the column you attempted to operate on','exceeds the number of columns in the matrix (on the left hand side of your expression).') mistake_true=mistake_true+1; err=1; end if(check>sizecheck(1,2)) sprintf('%s\n%s','Error: The index number of the column you attempted to operate on','exceeds the number of columns in the matrix (on the right hand side of your expression).') mistake_true=mistake_true+1; err=1; end if(multiplee>sizecheck(1,2)) sprintf('%s\n%s','Error: The index number of the column you attempted to add or subtract ','exceeds the number of columns in the matrix.') mistake_true=mistake_true+1; err=1; end if (check ~= operand) sprintf('%s \n\n%s \n\n%s \n\n%s','Inconsistency: You have entered an expression of the form: ',' cA = cB + JcK','The correct form is: ',' cA = cA + JcK') %no semi-colon to print to screen mistake_true=mistake_true+1; err=1; end if(mistake_true>0) RETURN=matrix; return end % scan for +,- sign using ASCII codes if (a(3,1)==43) sign_coeff=1; elseif (a(3,1)==45) sign_coeff= -1; end % execute colop matrix(:,operand)=matrix(:,operand) +sign_coeff*multiplier*matrix(:,multiplee); RETURN=matrix;