matlab矩阵保存到表格,将matlab求出的矩阵保存在Excel表格中
将matlab求出的矩阵保存在Excel表格中
转贴Genial分享程序
function xlswrite(m,header,colnames,filename);
%
xlswrite Easily create an Excel spreadsheet from MATLAB
%
% xlswrite(m,header,colnames,filename) creates a
Microsoft Excel
% spreadsheet using
% the MATLAB ActiveX interface. Microsoft Excel is required.
%
%Inputs:
% m Matrix to write to file
% (Optional):
% header String of header information.
% Use cell array for multiple lines
% DO NOT USE multiple row character arrays!!
% colnames (Cell array of
strings) Column headers.
% One cell element per column
% filename (string) Name of Excel
file. If not specified, contents will
% be opened in Excel.
%
% ex:
% m = rand(100,4);
% header = 'my data';
% %header{1} = 'first
line'; %This will give
% %header{2} = 'second
line'; % 2 header lines
% colnames =
{'Ch1','Ch2','Ch3','Ch4'};
%
% xlswrite(m,header,colnames,'myfile.xls');
% will save the spreadsheet as myfile.xls. The
user
% will never see Excel
% xlswrite(m,header,colnames);
% will open Excel with these contents in a new spreadsheet.
%
% Scott Hirsch
% The MathWorks
% This is provided free, no warranty, ...
% Copied from ActiveX example in documentation
[nr,nc] = size(m);
if nc>256
error('Matrix is too
large. Excel only supports 256 columns');
end;
% Open Excel, add workbook, change active worksheet,
% get/put array, save.
% First, open an Excel Server.
Excel = actxserver('Excel.Application');
%If the user does not specify a filename, we'll make Excel
visible
%If they do, we'll just save the file and quit Excel without ever
making
% it visible
if nargin<4
set(Excel, 'Visible',
1); %You might want to hide this if
% you autosave the file
end;
% Insert a new workbook.
Workbooks = Excel.Workbooks;
Workbook = invoke(Workbooks, 'Add');
% Make the first sheet active.
Sheets = Excel.ActiveWorkBook.Sheets;
sheet1 = get(Sheets, 'Item', 1);
invoke(sheet1, 'Activate');
% Get a handle to the active sheet.
Activesheet = Excel.Activesheet;
%Write header
if nargin<2 | isempty(header)
nhr=0;
elseif iscell(header)
nhr =
length(header); %Number header rows
for ii=1:nhr
ActivesheetRange = get(Activesheet,'Range',...
['A' num2str(ii)],['A' num2str(ii)]);
set(ActivesheetRange, 'Value', header{ii});
end;
else
nhr =
1; %Number header rows
ActivesheetRange =
get(Activesheet,'Range','A1','A1');
set(ActivesheetRange, 'Value',
header);
end;
�d column names
if nargin>2 &
~isempty(colnames)
nhr = nhr +
1; %One extra column name
ncolnames =
length(colnames);
for ii=1:ncolnames
colname = localComputLastCol('A',ii);
% cellname =
[char(double('A')+ii-1) num2str(nhr+1)];
cellname = [colname num2str(nhr)];
ActivesheetRange =
get(Activesheet,'Range',cellname,cellname);
set(ActivesheetRange, 'Value', colnames{ii});
end;
end;
% Put a MATLAB array into Excel.
FirstRow =
nhr+1; %You can change the first data row here.
% I start right after the headers
LastRow = FirstRow+nr-1;
FirstCol =
'A'; %You can change the first column here
LastCol = localComputLastCol(FirstCol,nc);
ActivesheetRange = get(Activesheet,'Range',...
[FirstCol num2str(FirstRow)],[LastCol num2str(LastRow)]);
set(ActivesheetRange, 'Value', m);
% If user specified a filename, save the file and quit
Excel
if nargin==4
invoke(Workbook, 'SaveAs',
[pwd filesep filename]);
invoke(Excel, 'Quit');
[pathstr,name,ext] =
fileparts(filename);
disp(['Excel file ' name '.xls
has been created.']);
end;
�lete the ActiveX object
delete(Excel)
function LastCol = localComputLastCol(FirstCol,nc);
% Comput the name of the last column where we will place data
%Input
% FirstCol (string) name of
first column
% nc total number of columns to write
%Excel's columns are named:
% A B C ... A AA AB AC AD .... BA BB BC ...
FirstColOffset = double(FirstCol) -
double('A'); %Offset from column A
if
nc<=26-FirstColOffset �sy if single letter
%Just convert to ASCII code,add the number of
needed columns,and convert back
%to a string
LastCol =
char(double(FirstCol)+nc-1);
else
ng =
ceil(nc/26); %Number of groups (of 26)
rm =
rem(nc,26)+FirstColOffset; %How many extra in this group beyond
A
LastColFirstLetter =
char(double('A') + ng-2);
LastColSecondLetter =
char(double('A') + rm-1);
LastCol = [LastColFirstLetter
LastColSecondLetter];
end;
使用方法:
>> m = rand(100,4);
>> header = 'my data';
>> colnames =
{'Ch1','Ch2','Ch3','Ch4'};
>> xlswrite(m,header,colnames,'myfile.xls');
Excel file myfile.xls has been created.
matlab矩阵保存到表格,将matlab求出的矩阵保存在Excel表格中相关推荐
- halcon 将数据保存到excel_halcon保存数据到excel表格-怎样把图像里面的数据提取到excel表格里面去?...
mt4如何将自定义数据保存到excel表格 这种方式嵌入的,目的就是让你没有办法简单复制粘贴.即使通过OCR之类的软件,由于存在底色.水印等,错误率也相当高,意义不是很大. 怎样把图像里面的数据提取到 ...
- Python爬虫鲁迅先生《经典语录》保存到Excel表格(附源码)
Python爬虫鲁迅先生<经典语录>保存到Excel表格(附源码) 前言 今天用Python 爬取鲁迅先生<经典语录>,直接开整~ 代码运行效果展示 开发工具 Python版本 ...
- 如何将物流信息导出保存在EXCEL表格里面,物流查询
很朋友在问如何查询物流信息并将查询到的物流信息导出表格保存,有需要的朋友可以看下这篇文章,小编将分享物流的查询方法,物流批量查询,查询完成后将物流信息导出保存在EXCEL表格里面,一起来看看吧! 第一 ...
- 对豆瓣进行爬虫来获取相关数据(分别保存到Excel表格和sqlite中)
1.存入Excel表格的代码: from bs4 import BeautifulSoup #网页解析,获取数据 import re #正则表达式,进行文字匹配 import urllib.reque ...
- Crawler:基于BeautifulSoup库+requests库+伪装浏览器的方式实现爬取14年所有的福彩网页的福彩3D相关信息,并将其保存到Excel表格中
Crawler:Python爬取14年所有的福彩信息,利用requests库和BeautifulSoup模块来抓取中彩网页福彩3D相关的信息,并将其保存到Excel表格中 目录 输出结果 核心代码 输 ...
- C语言试题二十三之编写一个函数void function(int tt[m][n],int pp[n]),tt指向一个m行n列的二维函数组,求出二维函数组每列中最小元素,并依次放入pp所指定一维数组中
1. 题目 请编写一个函数void function(int tt[m][n],int pp[n]),tt指向一个m行n列的二维函数组,求出二维函数组每列中最小元素,并依次放入pp所指定一维数组中.二 ...
- 用java查询excel表格_如何把java查询出的内容导入到excel表格
展开全部 java查询出的内容导入到excel表格 /**导出数据为XLS格式 * @param fos * @param bo */ public void writeExcelBo(FileOut ...
- 7.请编写一个函数int fun(int*s,int t,int *k),用来求出数组的最大元素在数组中的下标并存放在k所指的存储单元中。
7.请编写一个函数int fun(int*s,int t,int *k),用来求出数组的最大元素在数组中的下标并存放在k所指的存储单元中. 例如,输入如下整数:876 675 896 101 301 ...
- python爬取京东畅销榜(计算机类)图书信息(书名,作者,价格),并保存到excel表格
爬虫新手小白的第一次"半独立"爬虫,为什么是"半独立"呢?因为基本的代码块是从其他博客借鉴过来的,在此基础上加入了自己的思考和实现. (后面的价格获取感觉自己走 ...
最新文章
- “决胜算力时代 ”AI算力高端闭门分享会(7月21日)
- RxJs Subject, AnonymousSubject, BehaviorSubject, ReplaySubject和AsyncSubject
- Mars 如何分布式地执行
- NiFi导出自己模板和导入别人模板
- 学习是第一生产力——学习型组织众书读后感
- Ansible Synopsis
- FTP:226 transfer done but failed to open directory
- mysql数据库wait_timeout_mysql设置wait_timeout详解
- vue+element 表格el-table显示数据加载中
- 语法分析器的生成器——Bison
- 直流电机调速仿真作业
- 探索智慧医院落地新方案!OFweek 2019医疗物联网大会成功举办
- 为什么说10月24日是程序员的节日?
- 详解木头自动填表浏览器使用方法
- np.random用法
- 脱壳之压缩壳-FSG
- Redhat7.5上使用Pacemaker和Corosync搭建Nginx高可用系统
- 什么是VLAN?为什么要划分VLAN?
- Esxi 6.7使用 OVF Tool 导出 ova
- 优思学院|六西格玛黑带考试难不难?