MATLAB: Math operation matlab operation Hi, I have some problem here, case1, a=7, b=4, a/b = 1.75 case2, a=3, b=2, a/b = 1.5 I want variable "c" to become decimal value of a/b, c = 0.75 (for case 1), and c = 0.5 (case 2) wich matlab operation should I use? Best Answer a = 7;b = 4;c = rem(a / b, 1)orc = a / b;d = c - floor(c); Related SolutionsMATLAB: Avoiding for loop And another solution:A = [1 2 3 4 5]';B = [4 5 6 2 1]';index = B > A;C(index) = B(index) + A(index);nindex = ~index;C(nindex) = B(nindex) - A(nindex);And another one:f = 2 * (B > A) - 1;C = B + f .* A; MATLAB: Row vector divide by row vector It returns the scalar C (maxtrix 1x1) such thatC*B ~ Ain the sense that norm(C*B - A)^2 % or equivalentlysum((C*B - A).^2) is minimal.Illustration:>> sum((C*B-A).^2)ans = 5>> sum(((C+0.1)*B-A).^2) % move on the rightans = 5.1600>> sum(((C-0.1)*B-A).^2) % move on the leftans = 5.1600 >> ezplot(@(x) sum((x*B-A).^2), [-1 3]) % plot this function, that is a parabola minimum at x=1.25>> xline(A/B) Related QuestionExtract data from a text data.Matrix Multiplication (multiply every row of a matrix to different values)Matlab, operator A/B
Best Answer