Matlab读取和另存

来源:互联网 发布:php记录点击次数 编辑:程序博客网 时间:2024/05/01 06:17

一、Matlab另存为TXT

clear all;
close all;
clc;
 
A=[1,2;3,4];
Fid=fopen('test.txt','wt');
for i=1:2
    fprintf(Fid,'%10d%10d\n',A(i,1),A(i,2));
end
fclose(Fid);

二、读取和另存

txt数据如下图:
 0    4579   31814   89773  173361  272399  376933  478893  572330  653241  719282  769475  803998  824151  832600  833957  833957  833957  834600  834600  826608  815146  811916  811916  811916  811904  811540  809108  801419  785871  763042  737729  717129  706474  704560  704560  704560  705737  713111  730537  759404  798953  846860  899947  954825 1008366 1057962 1101635 1138013 1166243 1185859 1196641 1198490 1191345 1175163 1149956 1115890 1073417 1023416  967327  907242  845939  786779  733439  689407  657264  637866  629665  628359  628359  628359  630945  645375  673493  708732  741902  766577  781213  788041  790384  790735  790735  790735  791025  792665  796015  800574  805422 
 
matlab程序如下:
clear all;
clc;
fid1=fopen('motor1.txt','r');
motor1=fscanf(fid1,'%d ');
fclose(fid1);
 
A=load('motor1.txt');
 
size1=size(motor1);
for i=1:size1(1)
    motor1(i)=motor1(i)/(23*4000);
end
xlswrite('motor1.xls', motor1);%另存为excel格式
 
 
读取csv格式文件:
distance=xlsread('data_001.csv','B42:B701');

三、读取包含任意数据类型的规律数据

函数:textread


例如数据保存在test.dat中:
YAOBU-1.8     3.26102E-005         0.840973          176.942       NO       
        YAOBU-1.11     6.45224E-005          2.23194          173.244       NO       
        YAOBU-1.45     2.23892E-006         0.527337           177.65       NO       
        YAOBU-1.48       0.00559958          7.33617          163.588       NO       
       YAOBU-1.122        0.0035822          7.14721          162.253       NO       
       YAOBU-1.142       0.00116375          10.2233          159.765       NO       
       YAOBU-1.155       0.00592399         0.722135          96.5016       NO       
       YAOBU-1.257       0.00146776          10.5126          163.123       NO       
       YAOBU-1.287       0.00594193         0.267587              90.       NO       
       YAOBU-1.317       0.00381112         0.334876           90.918       NO       
       YAOBU-1.320        0.0342605          9.01046          149.769       NO

读取数据m文件:

clear all;
close all;
clc;
format long;
for i=2:4
    [c1 c2 c3 c4 c5]=textread('test.dat','YAOBU%f %f %f %f %s',i);
end


0 0
原创粉丝点击