From: Steven Lord on

"tinne123 " <nastanova(a)yahoo.co.uk> wrote in message
news:ht64j6$b0q$1(a)fred.mathworks.com...
> Hi Steve,
>
> thanks for your advise based on which I created
> --------------
> N = 2;
> for ii = 1:N
> S = load(sprintf('single%d.mat', ii),'a');
> load('joint.mat')
> apanel = S.a; end
> save('joint', 'apanel');
> ---------------
> It does not do what I want - namely put together apanel in joint.mat so
> that it contains a 15x1 from single1.mat and below it a 15x1 from
> single2.mat.

Preallocate apanel to be the size you want it to have when it's finished,
then fill it in during the loop.

N = 2;
apanel = zeros(15, N);
for ii = 1:N
S = load(sprintf('single%d.mat', ii));
apanel(:, ii) = S.a;
end

Note that this assumes that all the a's are 15-by-1; if not you may need to
use a cell array instead of a numeric matrix or array.

--
Steve Lord
slord(a)mathworks.com
comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ
To contact Technical Support use the Contact Us link on
http://www.mathworks.com


From: Sean on
"tinne123 " <nastanova(a)yahoo.co.uk> wrote in message <ht669h$3nl$1(a)fred.mathworks.com>...
> Thanks, Jos,
> but as said I am not able to write down a complete code that would do the task I need it to do. I have posted already some drafts, and also obtained a couple of partial tips. But at the moment I 'd really need somebody is that kind and writes down the few lines of a complete code. I still hope that it is an easy thing for one of the users. Thanks everybody, I am waiting for a rescueing post!

N = 2;
apanel = zeros(N*15,1);
idstart = size(apanel,1)-14
for k = 1:N
matfilename = sprintf('single%d.mat', k);
load(matfilename); %retrieve a
apanel(idstart:idstart+14) = a;
idstart = idstart-14; %NOTE this is not the for-loop variable
end
save('joint.mat','apanel');
From: Sean on
"Sean " <sean.dewolski(a)nospamplease.umit.maine.edu> wrote in message
> N = 2;
> apanel = zeros(N*15,1);
> idstart = size(apanel,1)-14
> for k = 1:N
> matfilename = sprintf('single%d.mat', k);
> load(matfilename); %retrieve a
> apanel(idstart:idstart+14) = a;
> idstart = idstart-14; %NOTE this is not the for-loop variable
> end
> save('joint.mat','apanel');

Doh! Those should be 15s. Ohwell, Steve Lord's implementation coupled with a (:) or reshape() at the end is better anyway.
From: tinne123 on
Sean,
thank you, I also tried to think in this way originally, but look, the proposed code results in
apanel =

0
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
2
3
4
5
6
7
8
9
10
11
12
13
14
15

I think it is better trying to append the matrix after each other.
From: tinne123 on
A big thank you Steve and Sean,

your posts were helpful. I am sorry for the strange "timing" of my last post, in reality I wrote it before I could see your last posts displayed.

Finally I came up with this:
-----------------------
load('joint.mat')
N = 2;
T = 15;
apanel = zeros(N*T,1);
save ('joint')
clear apanel;
for ii = 1:N
S = load(sprintf('single%d.mat', ii));
apanel((1+(ii-1)*T):(ii*T),1) = S.a;
save ('joint')
end
clear
--------------------------
so now apanel contains the a-s below each other.