MATLAB - excel 读取

matlab中excel 读取

  • [1. 写入excel文件 - xlswrite](#1. 写入excel文件 - xlswrite)
  • [2. 读取excel文件 - xlsread](#2. 读取excel文件 - xlsread)

1. 写入excel文件 - xlswrite

xlswrite(filename,A,sheet,xlRange)

javascript 复制代码
% ===== 写入字符串 ================================================
% 注意事项:Str需要是Cell格式,否则一个字母占一格
% ===============================================================
Str = {'abc'};
xlswrite('flux.xlsx',Str,'sheet4','A1');

% ===== 写入数组 =================================================
% 只需给出 arr(1,1) 对应的 'xlRange',一个数字一个格子
% ===============================================================
arr = rand(5);
xlswrite('flux.xlsx',arr,'sheet4','A2');

2. 读取excel文件 - xlsread

[num,txt,raw] = xlsread(filename,A,sheet,xlRange)

  • num :返回 [ 数值 ] 字段 ------ double格式
  • txt :返回 [ 文本 ] 字段 ------ cell格式
  • raw :返回 [ 数值、文本 ] 字段 ------ cell格式
javascript 复制代码
% ===== read excel data 【Example from matlab help]】 ============
[num,txt,raw] = xlsread('myExample.xlsx')
num =                  % num 中顺序下的字符以NAN表示
     1     2     3
     4     5   NaN
     7     8     9

txt =                 % txt 中数值不读取,以''表示
    'First'    'Second'    'Third'
    ''         ''          ''     
    ''         ''          'x'    

raw = 
    'First'    'Second'    'Third'
    [    1]    [     2]    [    3]
    [    4]    [     5]    'x'    
    [    7]    [     8]    [    9]
% ===============================================================

% ===== 只读取txt ================================================
[~,txt,~] = xlsread('flux.xlsx','sheet4','A1');
% ===============================================================
相关推荐
czhc11400756634 小时前
LINUX 820 shell:shift,expect
linux·运维·excel
大霞上仙16 小时前
实现自学习系统,输入excel文件,能学习后进行相应回答
python·学习·excel
CodeCraft Studio18 小时前
在 Python 中操作 Excel 文件的高效方案 —— Aspose.Cells for Python
python·ui·excel·报表·aspose·aspose.cells
Techie峰20 小时前
常见的 Bash 命令及简单脚本
chrome·bash·excel
小妖同学学AI20 小时前
deepseek一键生成word和excel并一键下载
人工智能·word·excel·deepseek
芒果很香1 天前
MFC中使用EXCEL的方法之一
excel·mfc
y1y1z1 天前
EasyExcel篇
java·excel
CHENFU_JAVA1 天前
EasyExcel 合并单元格最佳实践:基于注解的自动合并与样式控制
java·excel
cxyll12341 天前
从接口自动化测试框架设计到开发(三)主流程封装、返回数据写入excel
前端·python·excel
程高兴2 天前
遗传算法求解冷链路径优化问题matlab代码
开发语言·人工智能·matlab