Printing coordinate lines by XYZ array in a loop
11 views (last 30 days)
Show older comments
Deborah
on 10 Nov 2023
Edited: Walter Roberson
on 11 Nov 2023
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 Comments
Accepted Answer
Sulaymon Eshkabilov
on 11 Nov 2023
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 Comments
More Answers (1)
Sulaymon Eshkabilov
on 11 Nov 2023
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 Comments
See Also
Categories
Find more on Logical in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!