同じファイル内の複数のtxtドキュメントをmatlabで読み込む方法
2118 ワード
コード1
コード2
mydir=uigetdir;
if mydir(end)~='\'
mydir=[mydir,'\'];
end
dirs = dir([mydir,'*.txt']); %
dirs = struct2cell(dirs)';
n = length(dirs);
for i= 1:n
I = importdata(strcat(mydir,dirs{i}));
end
コード2
mydir='C:\Users\TSK\Desktop\test1';
bw = 'C:\Users\TSK\Desktop\haha\';
if mydir(end)~='\'
mydir=[mydir,'\'];
end
DIRS=dir([mydir,'*.bmp']); %
n=length(DIRS);
for i=1:n
if ~DIRS(i).isdir
img = imread(strcat(mydir,DIRS(i).name ));
%
img = rgb2gray(img);%
img = im2bw(img);%0-1
img=1-img;%
%SE=[0 1 0;1 1 1;0 1 0];%
SE=strel('square',2);
img=imdilate(img,SE,'same');%
name = strcat(bw,DIRS(i).name);
imwrite(img,name);
end
end