Printing coordinate lines by XYZ array in a loop
조회 수: 2 (최근 30일)
이전 댓글 표시
Hello, I am trying to convert a .csv file to G code for XYZ Positions.
Here is my code so far but I am not sure how to pass an array through the loop to get output changes as I change the .csv.
PosInput = readtable ('PositionData.csv');
PosArray = table2array(PosInput);
PosArray = PosArray';
XPos = PosArray(1,:)';
YPos = PosArray(2,:)';
ZPos = PosArray(3,:)';
for i = 1:XPos
fprintf('G0 X%d\n',i);
end
------------------------------------------------------
For example, the XPos array defined in the .csv file is [400,350]' .
I want to print 'G0 X400
G0 X350'
댓글 수: 0
채택된 답변
Sulaymon Eshkabilov
2023년 11월 11일
D = readmatrix('Data2G.csv');
D1 = D';
Xpos =D1(:,1:2);
Ypos =D1(:,3:4);
Zpos =D1(:,5:6);
for ii = 1:numel(Xpos(:,1))
fprintf('G0 X %d\n',Xpos(ii,:)');
end
% It can be also displayed:
for ii = 1:numel(Xpos(:,1))
fprintf('Position # %d \n',ii)
fprintf('G0 X %d\n', Xpos(ii,:)');
end
댓글 수: 0
추가 답변 (1개)
Sulaymon Eshkabilov
2023년 11월 11일
Most welcome. To add Y and/or Z is quite simple:
D = readmatrix('Data2G.csv');
D1 = D';
Xpos =D1(:,1:2);
Ypos =D1(:,3:4);
Zpos =D1(:,5:6);
for ii = 1:numel(Xpos(:,1))
fprintf('G0 X %d \n', Xpos(ii,:)');
fprintf('G0 Y %d \n', Ypos(ii,:)');
fprintf('G0 Z %d \n', Zpos(ii,:)');
fprintf(' \n')
end
% It can be also displayed:
for ii = 1:numel(Xpos(:,1))
fprintf('Position # %d \n',ii)
fprintf('G0 X %d \n', Xpos(ii,:)');
fprintf('G0 Y %d \n', Ypos(ii,:)');
fprintf('G0 Z %d \n', Zpos(ii,:)');
end
댓글 수: 0
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!