当前位置:网站首页>Method sharing of saving data to CSV file in MATLAB
Method sharing of saving data to CSV file in MATLAB
2022-07-24 03:36:00 【studyer_ domi】
A classmate asked a question , How to make matlab The data in the variable area is saved to csv In the document , So share Matlab Save data to csv Method of file .csv It's actually a txt, It's just csv It has a specific format txt nothing more , for instance , Edit a txt file , The contents are as follows

Change the suffix of this file name to csv, newly build Text document .csv, Then use excel open

So in matlab Save as csv In fact, and save as txt The method is similar to
1、 Method 1:table
% Matrix to be savedA=[1 2 3;4 5 6; 7 8 9];% Line namem=['m1';'m2';'m3'];% Column namecol={'test' 'c_1', 'c_2', 'c_3'};% Generate table , Generate by columnresult_table=table(m,A(:,1),A(:,2),A(:,3),'VariableNames',col);% Save tablewritetable(result_table, 'test.csv');
Use to assemble the data into table type , then writetable

If you don't need to set the header , Direct input
result_table1=table(A)writetable(result_table1, 'test1.csv');

But be careful ,writetable A header will also be generated according to the variable name , How to cancel this has not been found yet , Know how friends can confide in me

2、fopen
csv Format is a file that separates data with commas . The data between lines is separated by commas , Use... Between lines \n Separate . use MATLAB Write data to csv When you file , First use fopen Create a file with write permission , And then use fprintf Function writes data one by one . The data without newline is separated by commas , For line feed \n.
fid = fopen('test.csv', 'w+', 'n', 'utf8'); % Create a csv filefor i=1:3fprintf(fid, '%d,%d,%d\n', A(i,1),A(i,2),A(i,3)); % a line 3 Data , Separate with commas ; Add at the end of each line \n Line breakend

use fprint There is no method 1 The problem of automatically generating headers in
边栏推荐
- leetcode hot 100(刷題篇8)(232/88/451/offer10/offer22/344/)
- 数据湖:Apache Hudi简介
- Gpushare.com | 如何使用TensorBoardX可视化工具?
- Simulink代码生成: 可变子系统及其代码
- Exercices classiques de langue C (2) - « tri des bulles »
- Web3 traffic aggregation platform starfish OS gives players a new paradigm experience of metauniverse
- IDEA Clone的项目报Cannot resolve symbol ‘Override‘
- Lagrange polynomial
- leetcode hot 100(刷题篇8)(232/88/451/offer10/offer22/344/)
- [JS reverse hundred examples] a public resource trading network, reverse analysis of announcement URL parameters
猜你喜欢

C file operation details

Simulink代码生成: 可变子系统及其代码

JIRA automation experience sharing for 2 years

Data Lake: introduction to Apache Hudi

RTOS内功修炼记(十) | 深度解析RTOS内核上下文切换机制

H7-tool serial port offline burning operation instructions, support TTL serial port, RS232 and RS485 (2022-06-30)

MySQL learning - MySQL software installation and environment configuration (Windows) details!

Gpushare.com | 如何使用TensorBoardX可视化工具?

Leetcode-382. random nodes of linked list

C自定义类型详解
随机推荐
Hcip day 10 (initial BGP border gateway protocol)
Network parameter management
oh-my-zsh
Test interview questions
Express built-in Middleware
Svn: e00002: can't convert string from 'UTF-8' to native encoding problem solving
STL set container
leetcode hot 100(刷題篇8)(232/88/451/offer10/offer22/344/)
SolidWorks cannot reference references
Batch visual target detection callout box -- Yolo format dataset
[wepy2.0] installation
4. Hezhou air32f103_ LCD
Genesis public chain: Tamp the foundation of Web 3.0 development
SkyWalking分布式系统应用程序性能监控工具-上
Cve-2022-29464 wso2 file upload vulnerability
What are Caicai and qiniu doing? Is it safe to open an account?
Realize the communication before two pages (using localstorage)
PyTorch生态简介
Embedded system transplantation [5] - Cross compilation tool chain
93. (leaflet chapter) leaflet situation plotting - modification of attack direction