How to filter a variable by removing NaN on matlab
88 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Anthony Mukanya
el 17 de Ag. de 2015
Respondida: Pablo Oliveros
el 20 de Sept. de 2019
Hi guys,
I wrote the following code in an attempt to remove 'NaN' from a variable but I cannot run the code. Please help
clc
clear
format bank
data = xlsread;('Amortization Schedule.xlsx') % this command import the data from an excel spread sheet
for i = 1:1:308;
j = 1:1:6;
if data(i,j)= isnan(data(i,j))
data(i,j) = 0
end
end
I am trying to: firstly equate every 'NaN' to zero then I will proceed by writing other line of code to filter my data and only have values that are not zero.
I will appreciate the help in this matter.
Thanks
0 comentarios
Respuesta aceptada
James Tursa
el 17 de Ag. de 2015
Editada: James Tursa
el 17 de Ag. de 2015
You can skip the loops and just do this vectorized one-liner instead:
data(isnan(data)) = 0; % Set all NaN elements to 0 using logical indexing
Más respuestas (1)
Ver también
Categorías
Más información sobre Matrix Indexing en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!