24小时热门版块排行榜    

查看: 1627  |  回复: 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 ]
回复此楼

» 猜你喜欢

Retirement
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

monitor2885

至尊木虫 (知名作家)

队长

或者matlab能不能把csv文件转换成xls,然后再xlsread就行了
Retirement
2楼2009-10-15 22:39:08
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

change0618

铁杆木虫 (著名写手)

方丈大师

★ ★ ★ ★
monitor2885(金币+3,VIP+0): 10-15 23:55
sunxiao(金币+1,VIP+0):谢谢参与 10-16 02:53
你用load命令试一下
3楼2009-10-15 22:45:02
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

monitor2885

至尊木虫 (知名作家)

队长

u0=csvread('data.csv')不好用,因为我的文件第一行是文本,好像csvread要求所读取的csv文件必须都是数据。什么语句能删除csv文件里面的第一行,然后读取单元格A3到A10的数据?(假设csv里面有20*20的数据)

[ Last edited by monitor2885 on 2009-10-16 at 00:32 ]
Retirement
4楼2009-10-15 23:55:01
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

commonyue

新虫 (初入文坛)

★ ★
kuhailangyu(金币+1,VIP+0):欢迎积极参与 10-16 08:17
monitor2885(金币+1,VIP+0):什么语句能把csv数据导入xls里面? 10-16 16:46
可不可以先把csv的数据导入到xsl里面,然后处理呢。。。
5楼2009-10-16 03:41:19
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

change0618

铁杆木虫 (著名写手)

方丈大师

★ ★
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
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

monitor2885

至尊木虫 (知名作家)

队长

帮忙再看看
Retirement
7楼2009-10-16 13:35:35
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

monitor2885

至尊木虫 (知名作家)

队长

另外,要是我的csv文件的第一行是文字,用Matlab什么语句能删除第一行,其他不变,否则csvread不认识
Retirement
8楼2009-10-16 13:36:49
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

change0618

铁杆木虫 (著名写手)

方丈大师

我没有csv文件,没碰到过,你自己修炼吧。
9楼2009-10-16 13:53:57
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

change0618

铁杆木虫 (著名写手)

方丈大师

★ ★ ★ ★
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
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖
相关版块跳转 我要订阅楼主 monitor2885 的主题更新
普通表情 高级回复 (可上传附件)
最具人气热帖推荐 [查看全部] 作者 回/看 最后发表
[基金申请] 中青基了要发朋友圈吗? +7 349506619 2026-08-28 7/350 2026-08-31 13:39 by 冼亮淀粉酶
[基金申请] 29号明天会评吗 +4 笨笨唐 2026-08-28 4/200 2026-08-31 09:30 by huixian257
[基金申请] 基金不中,共勉 +12 eulota 2026-08-26 12/600 2026-08-31 08:42 by ZJTJZ
[基金申请] 能否申诉? +6 echo8914667 2026-08-30 7/350 2026-08-31 08:41 by kingkocxr
[基金申请] 为什么到现在没收到通知? +5 tannykie 2026-08-29 5/250 2026-08-30 21:05 by purplejack
[基金申请] 麻烦专家们看看评委们的意见(F口面上) +6 gdd2018 2026-08-28 11/550 2026-08-30 08:58 by 超级无敌华子
[基金申请] 我就是申请一个面上项目而已,这评审意见是按照杰青的条件评的吧? +6 gouxfjh 2026-08-28 11/550 2026-08-30 07:57 by gouxfjh
[基金申请] 国自然面上复盘~欢迎讨论 (金币+15) +15 晴天加油 2026-08-26 16/800 2026-08-29 18:28 by symmetry
[基金申请] 为什么资助数各大高校都创新高,自己申请怎么就这么难 +12 Kittylucky 2026-08-27 13/650 2026-08-29 00:04 by superceng
[基金申请] 基金系统什么内容也没有 30+4 winsaint 2026-08-27 9/450 2026-08-28 11:06 by maolC
[基金申请] 哪位高人中了,把查询到的截图贴出来让我看看,让我长长见识 +5 yuleib84 2026-08-26 6/300 2026-08-28 00:02 by yudaoqian88
[基金申请] 看板上这么多中的,有点像50人群里49个人都是骗子的那种感觉…… +5 a089 2026-08-26 6/300 2026-08-27 14:05 by jonewore
[基金申请] 怎么看青基中了没有啊 +5 叶九微 2026-08-26 5/250 2026-08-27 10:35 by l_zh2008
[基金申请] 我不理解! +15 Edward_pc 2026-08-26 23/1150 2026-08-26 20:34 by zzuzxg
[基金申请] 出来了 +9 trojank 2026-08-26 9/450 2026-08-26 14:25 by 宝贝虫子
[基金申请] 国合里面能看到了 +7 一怀馨秋 2026-08-26 7/350 2026-08-26 11:23 by zhaosm1982
[基金申请] 牛来!米来!面来! +8 beefly 2026-08-26 8/400 2026-08-26 08:37 by xuzhipiao
[基金申请] 在坚冰还盖着北海的时候,我看到了怒放的梅花。 (金币+10) +6 ziyangfang 2026-08-25 9/450 2026-08-25 20:26 by huagongfeihu
[基金申请] 某些机构,以效率低为荣,以效率低作为存在感 +9 yuleib84 2026-08-25 10/500 2026-08-25 17:14 by alexon
[基金申请] 没有任何消息-是不是就凉了 +9 图啦图啦 2026-08-24 10/500 2026-08-25 11:59 by 南海小哥
信息提示
请填处理意见