MATLAB: Same matrix but not equal problem isequal I have two matrix: C and C1, they are totally the same, but when I used isequal(C,C1) Matlab returns 0. could anyone help me figure why this happens? Best! Yu Best Answer When you see something that you do not understand, LOOK AT YOUR DATA.C(1,:)ans = Columns 1 through 31 NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN Columns 32 through 45 NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaNC1(1,:)ans = Columns 1 through 31 NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN Columns 32 through 45 NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaNisequal(NaN,NaN)ans = logical 0NaN == NaNans = logical 0NaNs are not equal to NaNs.nnz(isnan(C))ans = 543150numel(C)ans = 995220Roughly half of your array elements are NaN.You can test for equality, where NaNs are considered to be equal to NaNs, using isequaln.isequaln(C,C1)ans = logical 1 Related SolutionsMATLAB: Correlation between two row matrices Like that, each value of "a" is correlated to each value of "b", but applying the formula of the correlation, the correlation of two single numbers is NaN. To compute the correlation correctly, traspose the input vectorsresult = corr(a', b'); MATLAB: Finding values of specific range from table row or column >> A = [12345 NaN NaN NaN NaN 457 NaN NaN NaN 785 NaN NaN NaN NaN NaN NaN 74502].'A = 12345 NaN NaN NaN NaN 457 NaN NaN NaN 785 NaN NaN NaN NaN NaN NaN 74502Method one: accumarray:>> C = accumarray(cumsum(~isnan(A)),A,[],@(v){v});>> C{:}ans = 12345 NaN NaN NaN NaNans = 457 NaN NaN NaNans = 785 NaN NaN NaN NaN NaN NaNans = 74502Method two: mat2cell:>> X = diff(find([true;diff(isnan(A))<0;true]));>> C = mat2cell(A,X,1);>> C{:}ans = 12345 NaN NaN NaN NaNans = 457 NaN NaN NaNans = 785 NaN NaN NaN NaN NaN NaNans = 74502https://www.mathworks.com/help/matlab/matlab_prog/access-data-in-a-cell-array.html Related QuestionDoes a cell vector contains only NaNA(a==NaN) does not find NaN’s in matrix. What to doSubtract two matrices each with NaN values in different cellsConstructing an if statement when a column contains only one data point and the rest are NaNsFind the last NaN value in cell array and compare it with the next columnHelp with removing duplicate sub-elements….
Best Answer