Erase lines where NaN is included - fprintf

2 visualizaciones (últimos 30 días)
Tim Tolman
Tim Tolman el 3 de Abr. de 2015
Comentada: Tim Tolman el 3 de Abr. de 2015
Hi.
I can't figure out how to erase/delete lines from my fprintf, where NaN is included. Google only tells me how to erase NaN, but I need to erase the hole line, where NaN is included.
This is my code:
% X axis filename_x = 'Xakse.xlsx' ; x = xlsread(filename_x);
% Y axis filename_y = 'Yakse.xlsx' ; y = xlsread(filename_y);
% Z axix filename_z = 'input_til_gcode.xlsx' ; z = xlsread(filename_z);
s=5;
f = fopen('learningbydoing.txt', 'w'); Valueofx_mm = zeros(1,135); Valueofy_mm = zeros(1,135); Valueofz_mm = zeros(1,135);
for i=1:1:135
x_mm = x(i)*s;
Valueofx_mm(i) = x_mm;
y_mm = y(i)*s ;
Valueofy_mm(i) = y_mm;
z_mm = z(x(i),y(i));
Valueofz_mm(i)= z_mm;
fprintf(f,'G01 %2.2f %2.2f 0\n' ,Valueofx_mm(i), Valueofy_mm(i));
fprintf(f,'G01 %2.2f %2.2f %2.2f\n' ,Valueofx_mm(i), Valueofy_mm(i),Valueofz_mm(i));
end
fclose(f);
A part of the result is:
....
G01 85.00 85.00 NaN
G01 90.00 90.00 0
G01 90.00 90.00 NaN
G01 95.00 95.00 0
G01 95.00 95.00 NaN
G01 100.00 100.00 0
G01 100.00 100.00 18.01
G01 105.00 105.00 0
G01 105.00 105.00 19.25
..
How do I erase/delete the three lines (marked as bold)?
Best regards Tim

Respuesta aceptada

Mahdiyar
Mahdiyar el 3 de Abr. de 2015
Hi Tolman
To delet delete the row containing Nan, first, you have to detect the Nan you can use the command "isnan".
Regards,

Más respuestas (1)

Image Analyst
Image Analyst el 3 de Abr. de 2015
Just don't print them in the first place by checking if it's nan before printing:
if ~isnan(Valueofy_mm(i))
fprintf(f,'G01 %2.2f %2.2f 0\n' ,Valueofx_mm(i), Valueofy_mm(i));
end
if ~isnan(Valueofz_mm(i))
fprintf(f,'G01 %2.2f %2.2f %2.2f\n', ...
Valueofx_mm(i), Valueofy_mm(i),Valueofz_mm(i));
end

Categorías

Más información sobre NaNs 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