Erase lines where NaN is included - fprintf

1 view (last 30 days)
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

Accepted Answer

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

More Answers (1)

Image Analyst
Image Analyst on 3 Apr 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

Categories

Find more on Creating and Concatenating Matrices in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!