怎样从matlab中读取csv文件

怎样从matlab中读取csv文件,第1张

a = load 路径\inputtxt;
b = load 路径\outputtxt;

plot(a,b);

不过这还要看你的txt文件里面的数据是不是一行一行的放得了。
txt的文件要直接用load读,必须全为数字,而且每一行的列数要相等。如果有文字的行,必须以%开头。

TEK示波器读取的波形图数据存为csv,虽然用Excel可以直接打开,但是在Matlab里面读取的时候,csvread和xlsread用法还是有些不同的%Get data from a specified region in a sheet other than thefirst sheet:Numeric=xlsread(‘c:\matlab\work\myspreadsheet’,’sheet2’,’a2:j5’);M=CSVREAD(‘FILENAME’,R,C) reads data from the comma separatedvalue formatted file starting at row R and column C R and C arezero based so that R=0 and C=0 specifies the first value in thefile(如果数据行从15行开始,则R=14;从第一列开始则C=0)M=CSVREAD(‘FILENAME’,R,C,RNG) reads only the range specified byRND=[R1 C1 R2 C2] where (R1,C1)is the upper-left corner of the datato be read and (R2,C2) is the lower-right corner RNG can also bespecified using spreadsheet notation as inRNG=’A1B7’;想要确定添加个范围,比如A15:B10014,则RND=[14 0 10013 1]因为从示波器出来的图需要一些额外的数据处理才行,所以要进行一些运算;这些在得到了返回的M后就是一个数组,直接用就OK比如%找到第2列里面的最大值or最小值X=max(M(:,2)) or X=max(M(:,2))%返回最大值所在列的编号Num=find(M(:,2)==max(M(:,2)))%得到对应行第1列的值Y=M(find(M(:,2)==max(M(:,2))),1)M(:,1)=M(:,1)1E+08125;%min=min(M(:,2));%max=max(M(:,2));M(:,2)=(M(:,2)-min(M(:,2)))/(max(M(:,2))-min(M(:,2)));M(:,1)=M(:,1)-M(find(M(:,2)==max(M(:,2))),1);这样数据就处理完了,然后就是

第一种:M
=
CSVREAD('FILENAME')
,直接读取csv文件的数据,并返回给M,这时要求整个csv文件内容全部为用逗号隔开的数字,不能用其他字符。
第二种:M
=
CSVREAD('FILENAME',R,C)
,读取csv文件中从第R-1行,第C-1列的数据开始的数据,这对带有头文件说明的csv文件(如示波器等采集的文件)的读取是很重要的。

>> a=magic(5)
a =
17 24 1 8 15
23 5 7 14 16
4 6 13 20 22
10 12 19 21 3
11 18 25 2 9
>> csvwrite('csvtxt',a)
>> !type csvtxt
17,24,1,8,15
23,5,7,14,16
4,6,13,20,22
10,12,19,21,3
11,18,25,2,9


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/yw/13041726.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-29
下一篇 2023-05-29

发表评论

登录后才能评论

评论列表(0条)

保存