필터 지우기
필터 지우기

How to import data for files that have 11,12,13,2​1,22,23,31​,32,33 sequence?

조회 수: 2 (최근 30일)
Hi, I would like to import files from a directory. The files have the following sequence:
Data 11
Data 12
Data 13
Data 21
Data 22
Data 23
Data 31
Data 32
Data 33
I usually use the following general code for extracting a sequence of files:
numfiles = 3;
mydata = cell(1, numfiles);
for k = 1:numfiles;
myfilename = sprintf('Drift.out', k);
mydata{k} = importdata(myfilename);
end
Can anyone please advise me on how to modify it to suit the above files sequence?
Thank you very much. Regards, Ismail

채택된 답변

KSSV
KSSV 2017년 11월 11일
files = dir('*.out') ; % get all files with extension out
N = length(files) ; % toal number of files
% loop for each file
for i = 1:N
filename = files(i).name ;
% do what you want
end
  댓글 수: 4
KSSV
KSSV 2017년 11월 11일
What ever the names may be......it will list all the files present in the folder with extension out.
Ismail Qeshta
Ismail Qeshta 2017년 11월 11일
Thanks KSSV. I could not get the code right yet. I actually mean I need to identify the sequence of each file based on its name and permutation number in order to plot the data from the two files. I tried using this file, but I don't know what the thing that is wrong with it.
c = [1 2 3];
s = [1 2 3];
for i=1:3;
for j=1:3;
b=importdata['react.out', ij];
a=importdata['Drift.out', ij];
plot(a(:,2),-sum(b(:,2:11),2));
x= a(:,2);
y= -sum(b(:,2:11),2);
end
end

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 File Operations에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by