MATLAB: Inserting NaN for unknown data arraymatrix array I have one array say from (1:10)' I have a one more matrix [2, 100; 3, 450; 5, 500; 7, 800; 8, 850]; I want my final answer to be [1, NaN; 2, 100; 3, 450; 4, NaN; 5, 500; 6, NaN; 7, 800; 8, 850; 9, NaN; 10, NaN] Best Answer clc; clear all ;C = [1, NaN; 2, 100; 3, 450; 4, NaN; 5, 500; 6, NaN; 7, 800; 8, 850; 9, NaN; 10, NaN] ; A = (1:10)' ; B = [2, 100; 3, 450; 5, 500; 7, 800; 8, 850];iwant = NaN(10,2) ; iwant(:,1) = A ; [c,ia] = ismember(A,B(:,1)) ; iwant(c,2) = B(:,2) ; Related SolutionsMATLAB: How to select or group sections of an array without using indexing >> A = [NaN, NaN, NaN, NaN, 2, 3, 6, 7, NaN, NaN, NaN, NaN, NaN, 4, 6, 8, 8, NaN, NaN, NaN, NaN];>> X = diff([true,isnan(A),true]);>> B = find(X<0);>> E = find(X>0)-1;>> F = @(b,e) A(b:e);>> C = arrayfun(F,B,E,'uni',0);>> C{1}ans = 2 3 6 7>> C{2}ans = 4 6 8 8 MATLAB: Count number of values between NaN In = [NaN; NaN; NaN; NaN; 1; 1; 1; 1; NaN; NaN; NaN; 1; NaN; NaN; NaN; NaN; NaN; NaN; NaN; 1; NaN; NaN; NaN; NaN];[a,b] = rude(~isnan(In));a(b)rude is on the FEX Related QuestionMatch NaN’s in one Matrix to anotherCorrelation between two row matricesReplace numbers in a matrix depending on neighbor numbersSame matrix but not equal problemSubstracting matrix with NaN values
Best Answer