Erase lines where NaN is included - fprintf
이전 댓글 표시
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
채택된 답변
추가 답변 (1개)
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
카테고리
도움말 센터 및 File Exchange에서 Logical에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!