How can I import and then plot 16 files with .out extension using one for loop?

조회 수: 1 (최근 30일)
Burak Duran
Burak Duran 2020년 4월 14일
댓글: Burak Duran 2020년 4월 15일
Dear Friends,
My purpose is to import 16 different and sepearate files with .out extension and then plotting these files. The file names go like comb1.out, comb2.out, ....., comb16.out
In real life, I can have more than 16 files, let's say a thousand files.
A basic code is here;
A=1:16;
B=string(A);
for i=1:length(A)
C(i)=append("comb",B(i),".out");
end
C(1)="comb1.out", C(2)="comb2.out",...
But, here I have string values assigned to C; "comb1.out", "comb2.out" ... Converting them into Char does not work. After importing these files, I will try to plot them by using again for loops. I am very confused with the string&char&double conversion.
Anyway, the extension can be .xlsx or other types. The number of files can be more than 1000. Would you please tell me a general code to import any type of extension and then plot using for loops?
Thanks

답변 (1개)

Guillaume
Guillaume 2020년 4월 14일
"Would you please tell me a general code to import any type of extension"
There isn't. How you import a file completely depends on the actual format of the file, which may or may not be guessed from the extension. While typically .xlsx files are excel files which can be imported easily in matlab with readtable and co., the .out extension is not generally associated with a particular format. Different programs may use the .out extension for their files and they may all have different formats. If you're lucky, the file may be text which you may be able to import with readtable or some other text parsing function, but if the file is binary, you'd have to write your own decoder.
  댓글 수: 3
Stephen23
Stephen23 2020년 4월 14일
편집: Stephen23 2020년 4월 14일
"I do not want to write comb1.out and the plot(comb1.out(:,2),comb1.out(:,1)) 16 times."
Of course not, that is exactly what loops and arrays are for. There are two basic approaches, either:
  1. generate the filenames (e.g. from numeric using sprintf), or
  2. obtain the flenames from the OS using dir.
The MATLAB documentation already has examples for both of these:

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

카테고리

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