Treatment G-code file

1 回表示 (過去 30 日間)
K. Taieb
K. Taieb 2020 年 6 月 8 日
コメント済み: Rik 2020 年 6 月 8 日
Hello,
I have a G-code file as you can see in the following structure :
How I can with matlab to find the number of rows which carry the character of Z and to copy the instructions between two defined rows in another file .txt.
Thank you
  2 件のコメント
Rik
Rik 2020 年 6 月 8 日
It sounds like you can just read this file as text and use contains to look for a Z.
K. Taieb
K. Taieb 2020 年 6 月 8 日
Thank you Rik
I think contains returns a logical value. I want to find his position. My goal is to copy the instructions after the line that contains z.
str = fileread('gcode.txt');
caracter = "Z";
TF = contains(str,caracter)

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

採用された回答

Rik
Rik 2020 年 6 月 8 日
編集済み: Rik 2020 年 6 月 8 日
str = fileread('gcode.txt');
cell_str=strsplit(str,'\n')
character = 'Z';
TF = contains(cell_str,character);
line_num=find(TF);
  6 件のコメント
K. Taieb
K. Taieb 2020 年 6 月 8 日
Thank you!
Rik
Rik 2020 年 6 月 8 日
You're welcome. If you feel my answer solved your question, please mark it as accepted answer. If not, feel free to comment with your remaining issues.

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

その他の回答 (1 件)

Bjorn Gustavsson
Bjorn Gustavsson 2020 年 6 月 8 日
Maybe the easiest way it to loop through the text line-by-line and check if it contains the character 'Z' using strfind or findstr. Then it should be perfectly straightforward to keep the indices where you find your Zs.
HTH

カテゴリ

Help Center および File ExchangeLanguage Support についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by