# if column 1 is nan, make corresponding number in column2 nan

3 views (last 30 days)
C.G. on 30 Sep 2022
Edited: Cel Kulasekaran on 30 Sep 2022
I have the code below which randomly assigns 10% of the dataset to Nan. However this only turns column 1 to NaN. How can I make the corresponding number in column 2 also NaN?
Period = [1:1:100]';
F = [201:1:300]';
A=[Period F]; % a random matrix
Data = A;
percent_miss = 0.1;
nTime = length(Period);
Data(randperm(nTime,round(nTime*percent_miss))) = NaN;
##### 0 CommentsShowHide -1 older comments

Sign in to comment.

### Answers (2)

Cel Kulasekaran on 30 Sep 2022
Edited: Cel Kulasekaran on 30 Sep 2022
Re-writing your code, with suggestion:
Period = 1:100;
F = 201:300;
A = [Period', F']; % a random matrix
Data = A;
percent_miss = 0.1;
nTime = length(Period);
% adding this step for illustrative clarity
updateRows2NaN = randperm(nTime,round(nTime*percent_miss));
% you will want to apply this row-wise operation (i.e. across all columns)
Data(updateRows2NaN, :) = nan;
##### 0 CommentsShowHide -1 older comments

Sign in to comment.

Kevin Holly on 30 Sep 2022
Period = [1:1:100]';
F = [201:1:300]';
A=[Period F]; % a random matrix
Data = A;
percent_miss = 0.1;
nTime = length(Period);
Data(randperm(nTime,round(nTime*percent_miss))) = NaN;
LogicalofNans = isnan(Data(:,1));
Data(LogicalofNans,2)=nan;
##### 0 CommentsShowHide -1 older comments

Sign in to comment.

### Categories

Find more on Multirate Signal Processing in Help Center and File Exchange

### Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!