Printing coordinate lines by XYZ array in a loop
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Deborah
el 10 de Nov. de 2023
Editada: Walter Roberson
el 11 de Nov. de 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 comentarios
Respuesta aceptada
Sulaymon Eshkabilov
el 11 de Nov. de 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 comentarios
Más respuestas (1)
Sulaymon Eshkabilov
el 11 de Nov. de 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 comentarios
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!