MATLAB: How to merge two different tables using the first column in common join;merge A(class double) [1 7; 3 15] B(class double) [2 9; 5 10] C = (A+B) [1 7 0; 2 9 0; 3 15 0; 4 0 0; 5 0 10] Best Answer A = [1 7; 3 15]B = [2 9; 5 10]Ca = [A, zeros(size(A,1),1)];Cb = [B(:,1), zeros(size(B,1),1), B(:,2)];M1 = union(A(:,1),B(:,1));M2 = setdiff((1:max(M1))',M1);M3 = [M2, zeros(size(M2,1),2)];C = sortrows([Ca; Cb; M3],[1]); Related SolutionsMATLAB: Follow up: How to merge two different tables using the first column in common % data, (showing the drawback of storing relates things in different variables)A = [1 7; 3 15]B = [2 9; 5 10]C = [2 5; 3 4] % simple indexing engineA(:,3) = 2, B(:,3) = 3, C(:,3) = 4 % add column numbers to inputD = cat(1,A,B,C) sz = [max(D(:,1)), D(end,3)]m = zeros(sz)m(D(:,1), 1) = D(:,1)m(sub2ind(sz, D(:,1), D(:,3))) = D(:,2) MATLAB: How to combine two matrices C=[A;B]orC=vertcat(A,B) Related QuestionChanging value when first time a value appearsHow to change the value of zeros to first nonzero number below itHow to merge str array with double arrayDelete matrix row with certain valueHow to transform a matrix in his snake versionI have a marix of zeros(100*100) and i have 5 values of rows and cols in rc.(getting these values from another function). Now i want to make a new matrix B of same size as A(100*100) and want ones on that rows and cols provided by rc and zeros elseRanking of an array.
Best Answer