Printing coordinate lines by XYZ array in a loop
9 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Deborah
am 10 Nov. 2023
Bearbeitet: Walter Roberson
am 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 Kommentare
Akzeptierte Antwort
Sulaymon Eshkabilov
am 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 Kommentare
Weitere Antworten (1)
Sulaymon Eshkabilov
am 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 Kommentare
Siehe auch
Kategorien
Mehr zu Logical finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!