当前位置:首页 > 编程笔记 > 正文
已解决

MATLAB - excel 读取

来自网友在路上 165865提问 提问时间:2023-10-20 09:50:36阅读次数: 65

最佳答案 问答题库658位专家为你答疑解惑

matlab中excel 读取

  • 1. 写入excel文件 - xlswrite
  • 2. 读取excel文件 - xlsread

1. 写入excel文件 - xlswrite

xlswrite(filename,A,sheet,xlRange)

% ===== 写入字符串 ================================================
% 注意事项: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格式
% ===== read excel data 【Example from matlab help]============
[num,txt,raw] = xlsread('myExample.xlsx')
num =                  % num 中顺序下的字符以NAN表示1     2     34     5   NaN7     8     9txt =                 % 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');
% ===============================================================
查看全文

99%的人还看了

猜你感兴趣

版权申明

本文"MATLAB - excel 读取":http://eshow365.cn/6-20205-0.html 内容来自互联网,请自行判断内容的正确性。如有侵权请联系我们,立即删除!