Clean a given set of equations from every repeated equation. Clean a given set of equations from every repeated equation. The function checks one by one the given equations and create a new array with the same information as the input but without repeated equations. Prototype: [clearedEquations] = clearEquation( equations ) Input: equations - An array that has a single equation for every cell. The equations are all equal to 0, and you only need to specify the left member of every single equation without "= 0". Output: clearedEquations - An array that cointains the same information of the input, but without useless repeated equations.
0001 %Clean a given set of equations from every repeated equation. 0002 % 0003 %Clean a given set of equations from every repeated equation. The function 0004 %checks one by one the given equations and create a new array with the same 0005 %information as the input but without repeated equations. 0006 % 0007 %Prototype: [clearedEquations] = clearEquation( equations ) 0008 % 0009 %Input: equations - An array that has a single equation for every 0010 % cell. The equations are all equal to 0, and you only need to 0011 % specify the left member of every single equation without "= 0". 0012 % 0013 %Output: clearedEquations - An array that cointains the same information 0014 % of the input, but without useless repeated equations. 0015 0016 function [ clearedEquations ] = clearEquation( equations ) 0017 0018 %k is the current position in the output array. This index is used in order 0019 %to add further equations in the correct position in the output array. 0020 k = 1; 0021 0022 for i = 1:length(equations) 0023 repeated = false; 0024 0025 %Check if the i-th equation is repeated in the next equations. Doing 0026 %so, the last occorrence of an equation is the right one for the output 0027 %array. 0028 for j = (i+1):length(equations) 0029 if strcmp(char(equations(i)),char(equations(j))) 0030 repeated = true; 0031 end 0032 end 0033 0034 %If the i-th equation has no repetitions, it is added to the output 0035 %array at the k-th cell, and then k is increased by 1. 0036 if ~repeated 0037 clearedEquations(k) = equations(i); 0038 k = k + 1; 0039 end 0040 0041 end 0042 0043 return; 0044 0045 end