matlab读取txt文件为数组

clc;clear;close all;
rows = [1 180];%4行到17行。
cols = [1 1];%3到8列。
[FileName,PathName] = uigetfile('*.txt','Select the Txt files');%弹出对话框,然后选择你要处理的文件
fid = fopen([PathName FileName]);
temp = textscan(fid,'%s %s %s %s %s %s %s %s');
fclose(fid);
for i = 1:(rows(2)-rows(1)+1)
    for j = 1:(cols(2)-cols(1)+1)
        b = temp{j+cols(1)-1}{i+rows(1)-1};
        A(i,j) = str2num(b);
    end
end


B = reshape(A , 18 , 10 )
C = sum(B)

 

你可能感兴趣的:(笔记)