Erase lines where NaN is included - fprintf

2 ビュー (過去 30 日間)
Tim Tolman
Tim Tolman 2015 年 4 月 3 日
コメント済み: Tim Tolman 2015 年 4 月 3 日
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

採用された回答

Mahdiyar
Mahdiyar 2015 年 4 月 3 日
Hi Tolman
To delet delete the row containing Nan, first, you have to detect the Nan you can use the command "isnan".
Regards,
  1 件のコメント
Tim Tolman
Tim Tolman 2015 年 4 月 3 日
Thank you so much. It works perfectly!

サインインしてコメントする。

その他の回答 (1 件)

Image Analyst
Image Analyst 2015 年 4 月 3 日
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
  1 件のコメント
Tim Tolman
Tim Tolman 2015 年 4 月 3 日
Thank you so much. It works perfectly!

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeNaNs についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by