Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

The method of reading txt file by matlab

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly introduces the method of reading txt files by matlab, which has a certain reference value and can be used for reference by friends who need it. I hope you will learn a lot after reading this article. Next, let the editor take you to learn about it.

How matlab reads txt files: first put the text file into the working path of matlab; then use the importdata function to read the file or use the textread function to read it.

1. First of all, here is an example to make a txtde text file, such as the content of the following page.

2. Put the text file into the working path of matlab to facilitate reading operation. For example, if my text file is on the desktop, I can change the work path of matlab to the desktop. The specific method is to click the ellipsis after the current work path of matlab, pop up the option to select the folder, and then select the appropriate path.

3. Next, we use the importdata function to read the file. For example, I want to read a text file called data, which I can enter in the command window: data = IMPORTDATA ('in data.txt').

4. The results show that the data is a structured array. At this point, we can look at what each part of the structure represents. As shown in the following figure, the first array represents the number of text files, and the second and third arrays represent the Chinese characters in the text file. At this point, everyone can reference the corresponding array as needed.

5. In addition to the above functions, you can also use the textread function to read. When using this feature, you can specify the format of each part of the output content, which is used as follows: [a _ data.txt','%2s%.3f%.3f%.3f' _ b _ pr _ d] = format ('data.txt','%2s%.3f%.3f%.3f').

Where the second quotation mark of the textread indicates the format of the output. For example,% 2s means that the output format of the first column is in the form of a cell array,%. 3f means that the output number retains three decimal places.

Thank you for reading this article carefully. I hope it will be helpful for everyone to share the method of reading txt files by matlab. At the same time, I also hope that you will support us, pay attention to the industry information channel, and find out if you encounter problems. Detailed solutions are waiting for you to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report