Inserting NaN for unknown data

1 view (last 30 days)
Debasish Jana
Debasish Jana on 11 Jun 2020
Commented: Debasish Jana on 11 Jun 2020
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]

Accepted Answer

KSSV
KSSV on 11 Jun 2020
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) ;
  1 Comment
Debasish Jana
Debasish Jana on 11 Jun 2020
Thanks. I thought it could be done in 1 or 2 lines of code

Sign in to comment.

More Answers (0)

Categories

Find more on Matrices and Arrays 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!