MATLAB: Matrix arraymatrix I have a matrix S1 and S2 which consist of +1, -1 and 0. I want a matrix S such that it is +1 if there is +1 in both S1 and S2. -1 if there is -1 in both S1 and S2. 0 if anything else. Best Answer egS1 = randi([-1 1],10)S2 = randi([-1 1],10)solutionk= S1 + S2S = (k==2) - (k==-2)ORS = (S1 == 1 & S2 == 1) - (S1 == -1 & S2 == -1)MORE variantS = (S1 == S2).*S1orS = (S1 == S2).*S2 Related SolutionsMATLAB: I want to find the determinant for 5.5 matrix >> syms s1 s2 s3 s4 s5 s6 s7 s8 s9 s10>> M = [0 -s1 -s2 -s3 -s4; s1 0 -s5 -s6 -s4; s2 s5 0 -s8 -s9; s3 s6 s8 0 -s10; s4 s7 s9 s10 0];>> det(M)ans =s1*s4^2*s8^2 - s1*s4*s7*s8^2 - s2*s4^2*s6*s8 + s3*s4^2*s5*s8 - s3^2*s4*s5*s9 - s2^2*s4*s6*s10 + s3^2*s5*s7*s9 + s2^2*s6*s7*s10 + s2*s3*s4*s5*s10 + s2*s3*s4*s6*s9 + s1*s2*s4*s8*s10 - s1*s3*s4*s8*s9 - s2*s3*s5*s7*s10 - s2*s3*s6*s7*s9 + s2*s4*s6*s7*s8 - s3*s4*s5*s7*s8 - s1*s2*s7*s8*s10 + s1*s3*s7*s8*s9>> simplify(ans)ans =(s4 - s7)*(s3*s5 - s2*s6 + s1*s8)*(s2*s10 - s3*s9 + s4*s8) MATLAB: Input variable value to matrix syms s1 s2 s3subs(left_ARE,{s1, s2, s3}, {1, 5, 10}) Related QuestionMatlab solve indeterminate polynomial equations numericallyHow to add string to the beginning of each element in a string arrayError struct with fieldConcatenating the several matrices in a certain mannerSolving system of equations with parametersComparing k-medoids outputs
Best Answer