Identifying same values of two arrays
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Mia Dier
el 26 de Jun. de 2021
Respondida: Cris LaPierre
el 26 de Jun. de 2021
I have two string arrays: array1 and array2. I want to create a variable named change that is equal to 0 if array1 and array2 are equal or one of them is NaN and 1 otherwise.
array1 array2 change
A A 0
A A 0
A C 1
C C 0
C C 0
NaN B 0
3 comentarios
Scott MacKenzie
el 26 de Jun. de 2021
Further to @Soniya Jain's comment, what are A, B, and C in array1 and array2? Are they variables? Or, are they character or string literals? If they are variables, what type of data do they hold?
Respuesta aceptada
Cris LaPierre
el 26 de Jun. de 2021
Note that nan means not a number. When the rest of your data is chars or strings, nan actually gets convereted to <missing>.
array1 = ["A" "A" "A" "C" "C" nan]';
array2 = ["A" "A" "C" "C" "C" "B"]';
array1(ismissing(array1)) = array2(ismissing(array1));
array2(ismissing(array2)) = array1(ismissing(array2));
change = array1~=array2
0 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre Numeric Types en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!