• 如何在 matlab 和 excel之间进行数据导入导出操作?


    如何在 matlab 和 excel间进行数据导入导出?

     

    excel-->matlab 数据读取:

    A = xlsread('Excel路径+Excel的名称','工作表名称')

    例子:

    A = xlsread('创新班.xlsx','Sheet2')
    
    A = xlsread('创新班.xlsx','Sheet2','a1:c1') %读取a1 b1 c1的数据

    不写工作表名称,默认是第一个。


     matlab-->excel 数据写入:

    xlswrite('Excel路径+Excel的名称','需要输出的矩阵名称','工作表名称')

    例子:

    test = [1 2 3;4 5 6;7 8 9;10 11 12];
    
    xlswrite('test.xlsx',test,'Sheet2')
     1 angle = [-180 -165 -150 -135 -120 -105 -90 -75 -60 -45 -30 -15 0 15 30 45 60 75 90 105 120 135 150 165 180];
     2 
     3 CFX = [0.043011 0.055914 0.11613 0.24086 0.42581 0.62366 0.75699 0.7914 0.64946 0.4172 0.20215 0.08172 0.060215 0.13763 0.33978 0.61935 0.84301 0.96344 0.94194 0.84301 0.65806 0.44731 0.19355 0.055914 0.043011];
     4 
     5 CFY = [0.14383 0.083721 0.015027 -0.092308 -0.13524 -0.096601 0.01932 0.18247 0.25975 0.20823 0.045081 -0.10089 -0.19964 -0.74919 -0.80072 -0.71055 -0.5517 -0.28122 -0.015027 0.22111 0.38426 0.46583 0.44866 0.3585 0.14812];
     6 
     7 CMZ = [0.030108 0.056344 0.07957 0.083441 0.073118 0.054624 0.027527 -0.018495 -0.068387 -0.10495 -0.11183 -0.083871 -0.045161 0.037849 0.076989 0.04172 0.025376 0.0086022 0 -0.008172 -0.014624 -0.020645 -0.055484 -0.027097 0.030108];
     8 
     9 data = [angle', CFX', CFY', CMZ'];                   % 将数据组集到data
    10 [m, n] = size(data);            
    11 data_cell = mat2cell(data, ones(m,1), ones(n,1));    % 将data切割成m*n的cell矩阵
    12 title = {'angle', 'CFX', 'CFY', 'CMZ'};              % 添加变量名称
    13 result = [title; data_cell];                        % 将变量名称和数值组集到result
    14 s = xlswrite('wind.xls', result);                    % 将result写入到wind.xls文件中
  • 相关阅读:
    Python之print字典
    SpringBoot入门 (六) 数据库访问之Mybatis
    SpringBoot入门 (四) 数据库访问之JdbcTemplate
    SpringBoot入门 (三) 日志配置
    SpringBoot入门 (一) HelloWorld
    设计模式之装饰器模式
    设计模式之模板模式
    spring之mvc原理分析及简单模拟实现
    设计模式之单例
    国产密码研究
  • 原文地址:https://www.cnblogs.com/tsingke/p/12883003.html
Copyright © 2020-2023  润新知