insert NaNs where needed in matlab -
i have following 3 vectors , want insert nans
b
a
misses data points in an
. bn
should [0.1;0.2;0.3;nan;nan;0.6;0.7]
. how can bn? thanks.--jackie
a=[1;2;3;6;7]; an=[1;2;3;4;5;6;7]; b=[0.1;0.2;0.3;0.6;0.7];
okay first off, cant store string 'nan' 1 cell of matrix, must stored cell array. code snip below gives solution, if cell array okay output. please let me know questions or concerns might have.
forget italic parts, david k.
% nan solution jackie a=[1;2;3;6;7]; an=[1;2;3;4;5;6;7]; b=[0.1;0.2;0.3;0.6;0.7]; len = max(length(a),length(an)) bn = zeros(len,1); k = 0; % adjust index don't call b outside of size =1 :len ind= a(an(i)==a); if isempty(ind) ==1 bn(i) = nan(1,1) k = k+1; else bn(i) = b(i-k) end end
Comments
Post a Comment