Prev: live video tracking
Next: Make a animation with Matlab
From: tinne123 on 20 May 2010 15:17 Hi there, I am not sure how to make this code "copy" matrices "a" from the single1.mat and single2.mat files into matrix "apanel" in joint.mat file, below each other. Suppose, single1.mat contains: a = (1:1:15)'; single2.mat contains: a = (16:1:30)'; and joint.mat is empty. This draft code copies "a" from the first single file, but leaves the remainder of apanel unchanged. ----------------------------------- N = 2; for ii=1:N matfilename = sprintf('single%d.mat', ii); load(matfilename) T = 15; load('joint.mat') apanel = zeros(N*T,1); apanel((1+(ii-1)*T):(ii*T),:) = a; save ('joint') clear end ----------------------------------- As the bottom line to this simple example, I need to figure out how to transfer data between .mat files in general. Many thanks for corrections!!
From: Walter Roberson on 20 May 2010 15:26 "tinne123 " <nastanova(a)yahoo.co.uk> wrote in message <ht41rv$6uk$1(a)fred.mathworks.com>... > I need to figure out how to transfer data between .mat files in general. Use the function form of load(), work with the resulting structure(s), assigning or overwriting or removing fields, and save() the resulting structure using the -struct argument of save.
From: tinne123 on 20 May 2010 15:34 Hi Walter Robertson, thanks for your quick reply. I will try my best to go through it and apply your advise.
From: tinne123 on 20 May 2010 19:14 Hi again, I checked out in the helpfile "loading .mat file data into a structure" and also "saving -struct". Yet I do not understand how to I apply it, in case I need to extract data from a number of various .mat files into one "destination file". For now I really need to do as much as in the CODE POSTED ABOVE, really simple stuff. NOTE: maybe the difficulty arises from the fact that in each .mat file the variable of interest has the same name. This comes from the way the set of .mat files was generated. May I please ask, could someone check out the small code - is there a way to correct it? Guys have mercy, I have such a delay with a paper... Many thanks!!
From: Walter Roberson on 20 May 2010 19:46
"tinne123 " <nastanova(a)yahoo.co.uk> wrote in message <ht4fns$f70$1(a)fred.mathworks.com>... > I checked out in the helpfile "loading .mat file data into a structure" and also "saving -struct". Yet I do not understand how to I apply it, in case I need to extract data from a number of various .mat files into one "destination file". > For now I really need to do as much as in the CODE POSTED ABOVE, really simple stuff. > NOTE: maybe the difficulty arises from the fact that in each .mat file the variable of interest has the same name. This comes from the way the set of .mat files was generated. > May I please ask, could someone check out the small code - is there a way to correct it? We can't tell -- there is no obvious reason why you would want to write "a" into a portion of apanel, and it isn't clear that you are merging anything. No obvious relationship of T=15 to anything else either. for K = 1 : numfiles S = load(sprintf('foo%d.mat', K),'a'); if K == 1;apanel = zeros([size(a), numfiles]); end nd = ndims(a); indx = repmat({':'}, 1, nd); apanel(indx{:},K) = a; end clear S; save('destination.mat', 'apanel'); |