MATLAB: Represent the result of matrices manipulation as rational numbers rational Hi everyone I need to represent my resultant matrix with rational number rather than decimal point. for example I have matrix A = [ 1/2 1/3 ; 4 5/6] B = [ 2 1/4 ; 4 1 ] C = A+B how to get C as [ 5/2 7/12 ; 8 11/6] Best Answer format rat A = [ 1/2 1/3 ; 4 5/6]B = [ 2 1/4 ; 4 1 ] C = A+B Related SolutionsMATLAB: Matrix manipulation f = fopen('test.txt');c = textscan(f,'%f');fclose(f);out = reshape(c{:},[],3)' MATLAB: Matrix Manipulation A = [1; 1; 3; 1; 2; 1; 1; 1; 3; 1; 1; 1; 1; 2; 1; 1; 1; 1; 1; 3; 1; 1; 1; 2; 1; 1; 1; 1; 1; 2; 2; 1; 1; 1; 2; 1; 1; 2; 1; 1; 1; 1; 1; 1; 3; 1; 1; 3; 2; 1; 1; 1; 1; 1; 1; 1; 2; 2; 4; 1; 1; 2; 1; 1; 1; 1; 2; 2; 1; 1; 1; 3];a1=find(A==2)-1; %find the index of the 2a2=find(A==3)-1; %find the index of the 3a2=repmat(a2,2,1) %duplicate the 3 indexesB=sort([a1;a2])'; %join and sort the solution, also transpose%I transposed B because of your B example Related QuestionHow to copy rows of a matrix to convert it into single row?Vectors/rational numbers
Best Answer