Inserting NaN for unknown data
1 view (last 30 days)
Show older comments
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]
0 Comments
Accepted Answer
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) ;
More Answers (0)
See Also
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!