Concatenating data from a variable within a MAT file in a loop
1 view (last 30 days)
Show older comments
Within a loop, I want to 1) load a variable from a MAT file, 2) concatenate the newly loaded two-column data of varying lengths to a new variable array, and 3) save the variable to a new MAT file. I am fairly new to Matlab, but while I know how to add values to a given vector/array within a loop, this question has vexed me. Any suggestions?
EXAMPLE:
a=[load('fileA.mat','delta_length')];
b=[load('fileB.mat','delta_length')];
c=[load('fileB.mat','delta_length')];
new = [a.delta_length; b.delta_length; c.delta_length];
save('fileABC.mat','new');
In the above example, this is how I am doing it line by line, but the number of files I want to load could range from 1 to 10 or higher.
With my limited understanding I am trying something like this:
new=[];
for i=1:3
a_i=[load('fileA.mat','delta_length')];
new = [a_i.delta_length; ??how to keep appending a vector here??];
end
save('fileABC.mat','new');
Hopefully it's clear from this what I am trying to do. Any help much appreciated!
-Jason
0 Comments
Accepted Answer
Azzi Abdelmalek
on 3 Aug 2013
Edited: Azzi Abdelmalek
on 3 Aug 2013
new = [new;a_i.delta_length]
% Use also sprintf to generate fileA,fileB,...
new=[];
s='A':'C'
for i=1:3
a_i=[load(sprintf('file%s.mat',s(i)),'delta_length')];
new = [new;a_i.delta_length];
end
3 Comments
More Answers (0)
See Also
Categories
Find more on Debugging and Analysis in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!