MATLAB: How to make a NaN vector if there is a single NaN in a column homeworknanvector Say you have a vector A= [ 2 4 6 8 NaN 10 12 14] How do you make a NaN vector if and only if there is a NaN in one of the columnns: A = [NaN NaN NaN NaN NaN… ] Best Answer [m, n] = size(A); A = nan(m, any(isnan(A(:))) * n) Related SolutionsMATLAB: Find first non-NaN in each column of array & combine into one vector X = [2 NaN NaN NaN; 4 6 NaN NaN; NaN NaN NaN NaN; 5 4 7 8 ][m,n] = size(X);[I,J] = ndgrid(1:m,1:n);Xa = X;[~,r]=max(isfinite(Xa),[],1);Xa(I>r) = NaNXb = Xa;[~,c]=max(isfinite(Xb),[],2);Xb(J>c) = NaN[~,c]=max(isfinite(Xb),[],2);Xc = Xb(sub2ind([m,n],(1:m)',c)) MATLAB: Count and “synchronize” events in several columns A1=A(:,2:end);A1= any(~isnan(A1),2);out1 = bwlabel(A1);out1(~out1) = nan;out = [A,out1];orA1=A(:,2:end);A1= any(~isnan(A1),2);out1 = cumsum([false;diff(A1)==1]).*A1;out1(~out1) = nan;out = [A,out1]; Related QuestionConstructing an if statement when a column contains only one data point and the rest are NaNsHelp with removing duplicate sub-elements….How to find position of something
Best Answer