how to write a for loop for 4 screws which have x,y,z so that it get print

2 ビュー (過去 30 日間)
PA
PA 2022 年 7 月 4 日
コメント済み: PA 2022 年 7 月 5 日
SCREW;X;77
SCREW;Y;0
SCREW;Z;77

回答 (1 件)

Garmit Pant
Garmit Pant 2022 年 7 月 4 日
Hello Anwesha
You can use the following code snippet to write the data that you have provided into a text file.
x = [77,-60,-1.11; 120,-60,-1.11 ; 130,-60,-1.11; 140,60,-1.11];
fileID = fopen('exp.txt','w');
for i = 1:size(x,1)
fprintf(fileID, 'SCREW;X;%4.2f\n',x(i,1));
fprintf(fileID, 'SCREW;Y;%4.2f\n',x(i,2));
fprintf(fileID, 'SCREW;Z;%4.2f\n',x(i,3));
end
fclose(fileID);
You can read more about 'fprintf' to understand how text can be written into text files: https://www.mathworks.com/help/matlab/ref/fprintf.html
  8 件のコメント
PA
PA 2022 年 7 月 5 日
it worked but it takes the value of x for all the the three screw x, screwy, screw z
PA
PA 2022 年 7 月 5 日
thank you:)

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeData Type Conversion についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by