MATLAB: Matrix turning nans to 1 nan Hi all, I have a 294×1 matrix, and I want to convert all the NaNs to 1. If anybody could assist me I would be grateful. Thanky ou. Best Answer Let M be your matrix.M(isnan(M))=1; Related SolutionsMATLAB: Replace numbers in a matrix that are surrounded in 8-directions by NaNs to NaNs Try imfill(), then mask:% Create input matrix.m = [NaN NaN NaN NaN 1 0;NaN 1 NaN NaN 1 0;NaN NaN 1 NaN 1 0;NaN NaN 1 NaN NaN 0;NaN NaN NaN NaN NaN 0]% Create initial masknanLocations = isnan(m)% Fill holes in mask.mask = imfill(nanLocations, 'holes')% Create output matrix.output = m; % Initializeoutput(mask) = nan % This will assign nan to filled holes. MATLAB: Remove NaN from doubles within a cell array Try this:ab = {[1 2 NaN 3 4];[1 3 4 NaN 5 6 7 NaN]};Output = cellfun(@(x) x(isfinite(x)), ab, 'UniformOutput',false);Out1 = Output{1} % Display Output (Delete)Out2 = Output{2} % Display Output (Delete)Out1 = 1 2 3 4Out2 = 1 3 4 5 6 7 Related QuestionReplace numbers in a matrix depending on neighbor numbersReplacing null value with NaNHow to effectively assign values to different location in a TABLEAdd two matrices (element wise addition) together ignoring NaNs
Best Answer