clc;

clear all;

[numeric_data text_data rawdata] = xlsread('aaa.xls');

headings = rawdata(1,:)  % get headings from

first row

�ta = cell2mat(rawdata(2:end,:))  % get numeric

data from row 2 to end

1.

读取Excel文件

(a) 命令方式xlsread:

读取命令:[data,text]  = xlsread(FileName,

SheetName, Range);

data保存的是数据单元格的值, text保存的是字符串单元格的内容。

例如:[data,text]  = xlsread('C:\Test\test.xls'',

'testsheet', 'B2:D10');

[data,text,data_date]

= xlsread('C:\Test\test.xls'', 'testsheet',

'B2:D10');

存储方式为矩阵,和Excel表格中的位置一致。

如果Sheet内都是数据,可直接使用data = xlsread(文件名)。

(b) 界面方式uiimport:

在Matlab中输入命令:uiimport,

弹出如下窗口。不仅可以选择从文件导入,也可从剪贴板中导入。

2.

将MATLAB数据写入到Excel

写入命令:xlswrite(FileName, Output, SheetName, Range)

其中Output为要写入的数据,可以是矩阵也可以是cell类型

例如:xlswrite('C:\test\text.xls', eye(3), 'Sheet1', 'A1:C3')

10

% EF 230 import examples

clear all;

data1 = importdata('simple.txt');

data2 = dlmread('simple.txt','',1,0);

% skip one row (headings)

[numeric_data text_data rawdata] = xlsread('simple.xls');

headings = rawdata(1,:) % get headings from first row

data = cell2mat(rawdata(2:end,:))

% get numeric data from row 2 to end

% http://finance.yahoo.com/q/hp

clear all; close all; clc;

% define variables and build in pieces to make things easier to

modify

start_month = '00';

% month number is 0 based

start_day = '01';

start_year ='2011';

end_month = '01';

% 0 based

end_day = '20';

end_year ='2011';

stock = 'MSFT';

url = 'http://ichart.finance.yahoo.com/table.csv?ignore=.csv&g=d';

url = [url '&s=' stock];

url = [url '&a=' start_month '&b=' start_day '&c=' start_year];

url = [url '&d=' end_month '&e=' end_day '&f=' end_year];

% get the file from the web site

tmpfile='tmp.csv';

urlwrite(url,tmpfile);

% get data from the file into Matlab

data = dlmread(tmpfile,',',1,1);

data = flipud(data); % flip to get starting date at top

% plot the data

highlow(data(:,2),data(:,3),data(:,4),data(:,1));

title(url)

% Extra - set horizontal values to dates

% have to use importdata to get text values

A = importdata(tmpfile);

% A is a structure with fields data and textdata

% This file has the dates in column 1 starting at row

2

dates = A.textdata(2:end,1);

dates = flipud(dates);

% the next line will set the labels, but they can't be

rotated!

% set(gca,'XTick',1:length(dates),'XTickLabel',dates); % this sets

the labels

% workaround - create text objects

ylim = get(gca,'YLim');

% current range of plot

ypos = ylim(1)-.1; % adjust lower y down a little

set(gca,'XTickLabel',[]);

% turn off automatic labels

plotbox = get(gca,'position');

% current plot area

plotbox(2)=plotbox(2)+.1; % move bottom up 10%

plotbox(4)=plotbox(4)-.1; % make width 10% less

set(gca,'position',plotbox);

% set new values

% create text objects for each day

for i=1:length(dates)

text(i,ypos,dates{i},'Rotation',90,'horizontalalignment','right');

end

注:MATLAB中读写Excel的函数有

xlsfinfo检查文件是否包含excel表格;xlread读写excel文件;xlswrite写excel文件。

xlsread的调用格式为:

1. num=xlsread('filename')从excel文件filename的第一个工作页中读取所有的数据到double型数据num中。它忽略头行、头列、尾行、和尾列的所有单元为文本的行列,其他单元中的文本全部读取为NaN。

2. num=xlsread('filename',-1)手动框选要读取的数据块,返回到矩阵num中。

3. num=xlsread('filename',sheet)读filename中指定页的数据到矩阵中。

4. num=xlsread('filename','range')读filename中第一页的指定区域的数据到矩阵中。例如num=xlsread('a1.xls','A2:G2')

5. num=xlsrad('filename',sheet,'range')读filename中指定页、指定区域的数据到矩阵中。

6. num=xlsread('filename',sheet,'range','basic')以基本输入模式,读filename中指定页的数据到矩阵中,参数range被忽

略,sheet必须为带引号的字符串且区分字母大小写。这种模式限制了数据输入的能力,不将excel当作一个COM服务器。

7. [num,txt]=xlsread('filename',.......)读filename中的数据,返回数据double型数据到num中,文本数据到字符串单元数组txt中。txt中对应的数值数据的位置为空字符串。

8. [num,txt,raw]=xlsread('filename',.....)读filename中的数据,并返回数值数据到double型数组num中,非数值的文本到字符串单元数组txt中,未处理的单元数据到字符串单元数组raw中。raw中包含数值数据和文本数据。

matlab读数据写入excel文件路径,MATLAB读取和写入Excel文件相关推荐

  1. mysql properties文件路径_读取web项目properties文件路径 解决tomcat服务器找不到properties路径问题...

    1.需求:有时候我们产品经理给我们的需求是会不断变化的,例如数量是1000现在变成500,我们不可以去改代码吧,这样很麻烦,所以就可以改配置文件properties(这个数据库链接一样),当然也有js ...

  2. VB 获取路径名各部分 (获取文件路径,获取文件名,获取文件扩展名)自编

    '====================获取路径名各部分:  如: c:\dir1001\aaa.txt '============获取路径路径 c:\dir1001\ '============获 ...

  3. 【python图像处理】txt文件数据的读取与写入

    在使用python进行数据和图像处理的过程中,经常会遇到从txt文件中读取数据.已经将处理过程中的矩阵数据写入到txt文件的情形,如在伪彩映射中读取颜色映射表. 下面介绍几种我平时常用的txt文件数据 ...

  4. c#文件名去掉后缀_C#如何从文件路径中分离出文件名以及文件扩展名

    在C#文件操作的过程中或者Asp.Net文件的处理过程中,有时候知道文件的完整路径信息后,需要从完整路径中分离出文件名以及文件的后缀名等信息,此文将简要介绍C#语言如何从文件路径中分离出文件名以及文件 ...

  5. python读取文件路径格式_Python学习笔记读写文件之文件与文件路径

    随笔记录方便自己和同路人查阅. #------------------------------------------------我是可耻的分割线--------------------------- ...

  6. matlab中怎么获取文件路径,matlab获取文件路径和读写二进制文件

    1.matlab中处理路径和文件名,主要用到2个函数. [pathstr,name,ext,versn]=fileparts('filename'); fileparts函数返回文件路径各部分的信息, ...

  7. 怎么利用迭代器写入mysql_流迭代器实现文件操作(读取和写入)方法详解

    流迭代器并不知道底层流的特性.当然,它们只适用于文本模式,否则它们不会关心数据是什么.流迭代器可以以文本模式来读写任何类型的流.这意味着除了其他的一些流之外,我们可以用迭代器以文本模式来读和写文件.在 ...

  8. python读取文件路径乱码 linux_Python之pandas读写文件乱码的解决方法

    Python之pandas读写文件乱码的解决方法 python读写文件有时候会出现 'XXX'编码不能打开XXX什么的,用记事本打开要读取的文件,另存为UTF-8编码,然后再用py去读应该可以了.如果 ...

  9. java读写excel poi_Java使用POI读取和写入Excel指南

    做项目时经常有通过程序读取Excel数据,或是创建新的Excel并写入数据的需求: 网上很多经验教程里使用的POI版本都比较老了,一些API在新版里已经废弃,这里基于最新的Apache POI 4.0 ...

  10. python输出csv文件-Python之读取与写入CSV文件

    原标题:Python之读取与写入CSV文件 本文作者:闫续文 文字编辑:张梦婷 技术总编:张学人 有问题,不要怕!访问 CSV(Comma-Separated Values)格式是电子表格和数据库最常 ...

最新文章

  1. CDN 二级回源实现
  2. gpg keys for php 5.5,Fedora解决/etc/pki/rpm-gpg/RPM-GPG-KEY-fedora-x86_64问题
  3. 隐藏GridControl的“Drag a column header here to group by that column”
  4. python spider怎么用_python爬虫入门(七)Scrapy框架之Spider类
  5. java有string这个类型吗_关于java的String类型
  6. python 批量重命名文件_Python批量重命名文件的方法
  7. Spring-Bean配置-使用外部属性文件(转)
  8. [转]隐马尔科夫模型HMM
  9. mac无法充电解决办法!快来get下吧!
  10. pytest(2) pytest与unittest的区别
  11. 递归求最大公约数和最小公倍数
  12. 方舟原始恐惧mod生物代码_方舟MOD
  13. 推荐一些小而美的互联网公司
  14. ROS2 C++ Subscriber Publisher 订阅发布例子
  15. shell获取脚本本身名称_linux,shell脚本中获取脚本的名字,使用脚本的名字。
  16. 大华linux密码,Linux用户和组的实战练习
  17. JVM: java虚拟机
  18. linux下.tar.gz和.gz文件解压详解
  19. Echart.js China.js制作中国热力图
  20. TRPO:信赖域策略优化

热门文章

  1. sparql入门-中文教程
  2. App渠道打包的最佳攻略,一次解决打包难题
  3. Qt quick性能提升[通俗易懂]
  4. fpc : 调用 MS TTS 读中英文
  5. 股市顶尖高手超短秘诀
  6. JavaScript-冻结对象
  7. Revit二次开发-根据名称获取标高
  8. 家庭助理简介(home assistant)
  9. “云时代”大势当前,专有云成企业上云首选
  10. 后缀是php,php是什么文件_文件后缀php是什么意思