How I can create a vector with specified blanks?
이전 댓글 표시
Hi,I have a time series of daily data for 4 years(4*365 data) and I would like to have a some of daily data to be blanks(gaps) to do some analysis on the rest. My problem is that how I can create a specified length gaps,for example 3 days,on my vector data.Is there any script to create artificial gaps with specific gap length?
채택된 답변
추가 답변 (3개)
Azzi Abdelmalek
2016년 7월 5일
You can set your data to nan
Data=rand(4*365,1) % your data
idx_gap=10:12
Data(idx_gap)=nan
댓글 수: 3
Rita
2016년 7월 5일
Azzi Abdelmalek
2016년 7월 5일
Data=randi(10,20,1) % your data
freq=3
period=6
ii=1:period:numel(Data)
idx=bsxfun(@plus,ii',1:3)
Data(idx)=nan
Rita
2016년 7월 5일
Image Analyst
2016년 7월 5일
Try this:
data = randi(9, 1, 300) % Create sample data.
% Get location of starts of 15 nan runs
nanStartLocations = sort(randperm(length(data)-3, 15))
% Find the ending indexes of each run
nanEndLocations = nanStartLocations + 3
% Assign nans. Note, there may be overlap so that some stretches may be more than 3 long.
for k = 1 : length(nanStartLocations)
data(nanStartLocations(k):nanEndLocations(k)) = nan;
end
data % Print to command window.
댓글 수: 2
Rita
2016년 7월 5일
Image Analyst
2016년 7월 5일
If you want to make sure that no runs of 3 nans overlay with any other run of 3 nans, then you're going to have to check for that while you're assigning them. Change the for to a while and then check the elements to see if any are already nan. If any are, then use "continue" to skip to the bottom of the while loop. If none are, then do the assignment and increment your count. Keep going until you've added the required number of nan runs. It's not hard. Give that a try. You might try isnan() to get a list of what elements are nan.
Javad Beyranvand
2022년 5월 2일
Data=rand(4*365,1) % داده های شما idx_gap=10:12 داده(idx_gap)=nan
if true
% code
end
카테고리
도움말 센터 및 File Exchange에서 NaNs에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!