How to read the contents of .txt and display its contents in my gui.
조회 수: 4 (최근 30일)
이전 댓글 표시
How to read the contents of .txt and display its contents in my gui.
For example: I want to display the text of 1.txt to edit1, edit2, edit3 in my gui.


please help me
댓글 수: 0
답변 (1개)
Aravind
2025년 2월 8일
To display the contents of a .txt file in your MATLAB GUI using App Designer, you can follow the following steps.
Read the File: Use the “fopen” function to open the file, which returns a file identifier for reading. Depending on your needs, use “fread” to read the entire file as a character array or “fgets” to read the file line by line. After reading, ensure you close the file with “fclose” to free up system resources. You can learn more about these functions by using the following commands in the MATLAB Command Window:
doc fread %for fread
doc fgets %for fgets
doc fclose %for fclose
Parse the Contents: Once you have read the file, parse the contents to extract the necessary data.
Display in GUI: Use the parsed information to update the Edit Fields in your App Designer GUI. Set the “Value” property of these fields to the parsed text to display the information in the GUI. You can find more information about the "EditField" by running the following command in the MATLAB Command Window:
doc EditField
I hope this helps you achieve your goal!
댓글 수: 1
Walter Roberson
2025년 2월 8일
In the time since the question was asked, MATLAB added a readlines function, which reads a given file name and returns a string array of text. You could then set the Value property of a uitextarea
참고 항목
카테고리
Help Center 및 File Exchange에서 Workspace Variables and MAT Files에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!