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

2 visualizzazioni (ultimi 30 giorni)
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?

Risposta accettata

Wilson A N
Wilson A N il 19 Gen 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

Più risposte (1)

Walter Roberson
Walter Roberson il 19 Gen 2017

Categorie

Scopri di più su Creating and Concatenating Matrices in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by