Inserting NaN for unknown data

1 visualización (últimos 30 días)
Debasish Jana
Debasish Jana el 11 de Jun. de 2020
Comentada: Debasish Jana el 11 de Jun. de 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]

Respuesta aceptada

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

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Matrices and Arrays en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by