How can I automatically load multiple data files and insert it into one matrix?

3 visualizaciones (últimos 30 días)
I have 10 .mat files with 5 variables each. I want to load them automatically in MATLAB into one Matrix were the values of the variables are inserted one after another. And I want to insert a counter on the right that tells me the number of the file.
[Var1 Var2 Var3 Var4 Var5 Counter
Valfile1 Valfile1 Valfile1 Valfile1 Valfile1 1
Valfile1 Valfile1 Valfile1 Valfile1 Valfile1 1
Valfile1 Valfile1 Valfile1 Valfile1 Valfile1 1
Valfile2 Valfile2 Valfile2 Valfile2 Valfile2 2
Valfile2 Valfile2 Valfile2 Valfile2 Valfile2 2
Valfile2 Valfile2 Valfile2 Valfile2 Valfile2 2
...
Is that possible with a for loop?

Respuesta aceptada

Wilson A N
Wilson A N el 19 de En. de 2017
Yes it is possible. You just have to print the index indicating from which file you are currently loading the data. You can see the sample code given below:
k = [];
FileName = {'file1.mat','file2.mat','file3.mat'};
for i = 1:3
k = [k; importdata(FileName{i}) i*ones(5,1)];
end

Más respuestas (1)

Walter Roberson
Walter Roberson el 19 de En. de 2017

Categorías

Más información sobre Creating and Concatenating Matrices en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by