| 查看: 1442 | 回复: 11 | |||
| 当前主题已经存档。 | |||
monitor2885至尊木虫 (职业作家)
队长
|
[交流]
【求助】Matlab怎么读入csv文件
|
||
|
function test clear clc global u yy u0=xlsread('data.csv','A2:A12');%有错误提示呀 t0=0:1:10; y0=[0 2]; tt=[];yy=[]; for i=1:length(t0)-1 t=[t0(i), t0(i+1)]; u=u0(i); [t,y]=ode45(@ivpodefun,t,y0); y0=y(end,: ); tt=[tt;t]; yy=[yy;y]; end figure plot(tt,yy(:,1),'ro-',tt,yy(:,2),'b^-') function dydt=ivpodefun(t,y) global u dydt=[y(2);u*(1-y(1)^2)*y(2)-y(1)]; 我的csv文件就在上传的压缩包里面。谢谢了 [ Last edited by monitor2885 on 2009-10-16 at 13:33 ] |
» 猜你喜欢
全日制(定向)博士
已经有5人回复
假如你的研究生提出不合理要求
已经有10人回复
萌生出自己或许不适合搞科研的想法,现在跑or等等看?
已经有4人回复
Materials Today Chemistry审稿周期
已经有4人回复
参与限项
已经有3人回复
实验室接单子
已经有4人回复
对氯苯硼酸纯化
已经有3人回复
求助:我三月中下旬出站,青基依托单位怎么办?
已经有12人回复
所感
已经有4人回复
要不要辞职读博?
已经有7人回复

monitor2885
至尊木虫 (职业作家)
队长
- 应助: 6 (幼儿园)
- 贵宾: 0.339
- 金币: 38700.5
- 散金: 147
- 红花: 22
- 帖子: 4943
- 在线: 2166.8小时
- 虫号: 701577
- 注册: 2009-02-15
- 性别: GG
- 专业: 生态系统生态学

2楼2009-10-15 22:39:08
change0618
铁杆木虫 (著名写手)
方丈大师
- 应助: 44 (小学生)
- 金币: 17724.5
- 红花: 17
- 帖子: 2413
- 在线: 546.7小时
- 虫号: 496517
- 注册: 2008-01-19
- 专业: 化学反应工程
3楼2009-10-15 22:45:02
monitor2885
至尊木虫 (职业作家)
队长
- 应助: 6 (幼儿园)
- 贵宾: 0.339
- 金币: 38700.5
- 散金: 147
- 红花: 22
- 帖子: 4943
- 在线: 2166.8小时
- 虫号: 701577
- 注册: 2009-02-15
- 性别: GG
- 专业: 生态系统生态学

4楼2009-10-15 23:55:01
5楼2009-10-16 03:41:19
change0618
铁杆木虫 (著名写手)
方丈大师
- 应助: 44 (小学生)
- 金币: 17724.5
- 红花: 17
- 帖子: 2413
- 在线: 546.7小时
- 虫号: 496517
- 注册: 2008-01-19
- 专业: 化学反应工程
★ ★
nono2009(金币+1,VIP+0):谢谢交流!欢迎常来。 10-16 10:40
monitor2885(金币+1,VIP+0):有错误提示,怎么回事 10-16 13:34
nono2009(金币+1,VIP+0):谢谢交流!欢迎常来。 10-16 10:40
monitor2885(金币+1,VIP+0):有错误提示,怎么回事 10-16 13:34
![]() ![]() 你help csvread一下不就出来了啊 u0=csvread('data.csv','A3:A10') 也许上边的用法不对,我help一下用法是 M = CSVREAD('FILENAME',R,C) reads data from the comma separated value formatted file starting at row R and column C. R and C are zero- based so that R=0 and C=0 specifies the first value in the file. M = CSVREAD('FILENAME',R,C,RNG) reads only the range specified by RNG = [R1 C1 R2 C2] where (R1,C1) is the upper-left corner of the data to be read and (R2,C2) is the lower-right corner. RNG can also be specified using spreadsheet notation as in RNG = 'A1..B7'. 我不知道csv文件里面的内容是什么形式的 [ Last edited by change0618 on 2009-10-16 at 14:22 ] |
6楼2009-10-16 09:14:07
monitor2885
至尊木虫 (职业作家)
队长
- 应助: 6 (幼儿园)
- 贵宾: 0.339
- 金币: 38700.5
- 散金: 147
- 红花: 22
- 帖子: 4943
- 在线: 2166.8小时
- 虫号: 701577
- 注册: 2009-02-15
- 性别: GG
- 专业: 生态系统生态学

7楼2009-10-16 13:35:35
monitor2885
至尊木虫 (职业作家)
队长
- 应助: 6 (幼儿园)
- 贵宾: 0.339
- 金币: 38700.5
- 散金: 147
- 红花: 22
- 帖子: 4943
- 在线: 2166.8小时
- 虫号: 701577
- 注册: 2009-02-15
- 性别: GG
- 专业: 生态系统生态学

8楼2009-10-16 13:36:49
change0618
铁杆木虫 (著名写手)
方丈大师
- 应助: 44 (小学生)
- 金币: 17724.5
- 红花: 17
- 帖子: 2413
- 在线: 546.7小时
- 虫号: 496517
- 注册: 2008-01-19
- 专业: 化学反应工程
9楼2009-10-16 13:53:57
change0618
铁杆木虫 (著名写手)
方丈大师
- 应助: 44 (小学生)
- 金币: 17724.5
- 红花: 17
- 帖子: 2413
- 在线: 546.7小时
- 虫号: 496517
- 注册: 2008-01-19
- 专业: 化学反应工程
★ ★ ★ ★
wuguocheng(金币+4,VIP+0):谢谢参与 10-16 16:40
wuguocheng(金币+4,VIP+0):谢谢参与 10-16 16:40
|
function outputStuff = mfcsvread(fileName) %mfcsvread reads a CSV file containing both text & numeric data. MATLAB's %csvread function will work with all numeric, or all text data, but not %both. It's common to have a file with a single line of comma separated %text headers followed by many rows of numeric data. xlsread is limited in %the number of rows & colums (actually, Excel is the limitation) it can %read. % % The CSV file should look like: % comma, separated, text, ... % 1,2,3,4,5,... % 6,7,8,9,10,... % etc... % % The output is a structure with the column headers as fields in a % structure each with a vector of data. % Open the file fid=fopen(fileName); % Start reading the data tline = fgetl(fid); % Read in the first line only (text headers) tline = tline(tline~=' '); %Get rid of any spaces commaLocs=findstr(',',tline); % find the commas fieldNames=cell(1,(length(commaLocs)+1)); start=1; for colIdx=1:length(commaLocs) fieldNames{colIdx}=tline(start:commaLocs(colIdx)-1); start=commaLocs(colIdx)+1; end fieldNames{colIdx+1}=tline(start:end); %Read in the rest of the data (should be numeric) fieldData=csvread(fileName,1,0); %Convert the data into a single structure. [cellW cellH]=size(fieldNames); numFields=max([cellW cellH]); %Needs to be a 1xN or Nx1 cell-array. if ~iscell(fieldNames) disp('Needs to be a cell-array'); return; elseif cellW ~=numFields && cellH ~=numFields disp('Needs to be 1xN or Nx1'); return; end dataSize=size(fieldData); arrayDim=find(dataSize==numFields); if isempty(arrayDim) disp('Dimensions are wrong'); end outputStuff=[]; if arrayDim==2 for idx=1:numFields outputStuff.(fieldNames{idx})=fieldData(:,idx); end else for idx=1:numFields outputStuff.(fieldNames{idx})=fieldData(idx,: ); end end [ Last edited by change0618 on 2009-10-16 at 14:24 ] |
10楼2009-10-16 14:16:15












回复此楼
