Printing coordinate lines by XYZ array in a loop
24 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Deborah
le 10 Nov 2023
Modifié(e) : Walter Roberson
le 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 commentaires
Réponse acceptée
Sulaymon Eshkabilov
le 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 commentaires
Plus de réponses (1)
Sulaymon Eshkabilov
le 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 commentaires
Voir également
Catégories
En savoir plus sur Logical dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!