Thread Subject: Merge the small matrixes into a big one

Subject: Merge the small matrixes into a big one

From: Q Zhang

Date: 1 Nov, 2009 14:06:01

Message: 1 of 3

Dear All,

I was runing a loop in which every step generates a 3*1 vector as a result, and I need to store all these matrixes into a big one. Since the line and colum indices are mismatched with the result, the result doesn't comes out. Can anyone help me about it? Many thanks in advance?!

Below is my loop:
for i=1:n
    for j=1:m
    [mu(i,j),FVAL,EXITFLAG,OUTPUT,LAMBDA,GRAD,HESSIAN] = ...
    fmincon(@myfun,mu0,[],[],[],[],lbe,ube,[],options,m2,m3(i),m4(i),w(j));
    end
end

mu=mu; %% should be a (3*n,3*m) matrix

%% in each step of the loop, mu is a 3*1 vector

QZ

Subject: Merge the small matrixes into a big one

From: Matt Fetterman

Date: 1 Nov, 2009 17:49:01

Message: 2 of 3

"Q Zhang" <silence_qunzi@hotmail.com> wrote in message <hck4k9$if$1@fred.mathworks.com>...
> Dear All,
>
> I was runing a loop in which every step generates a 3*1 vector as a result, and I need to store all these matrixes into a big one. Since the line and colum indices are mismatched with the result, the result doesn't comes out. Can anyone help me about it? Many thanks in advance?!
>
> Below is my loop:
> for i=1:n
> for j=1:m
> [mu(i,j),FVAL,EXITFLAG,OUTPUT,LAMBDA,GRAD,HESSIAN] = ...
> fmincon(@myfun,mu0,[],[],[],[],lbe,ube,[],options,m2,m3(i),m4(i),w(j));
> end
> end
>
> mu=mu; %% should be a (3*n,3*m) matrix
>
> %% in each step of the loop, mu is a 3*1 vector
>
> QZ

Here are two possible ways:
1. make a cell array, so that A{i,j}=X, where X is the 3x1 matrix.
2. Expand your indices, so that:
Aindex=i*3 Bindex=j
P(Aindex,Bindex)=X, where X is the 3x1 matrix
The resulantant matrix mu should be (3*n,m)

Subject: Merge the small matrixes into a big one

From: Q Zhang

Date: 2 Nov, 2009 09:07:00

Message: 3 of 3

Hi Matt,

many thanks for your help :))

Tags for this Thread

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

rssFeed for this Thread

Contact us at files@mathworks.com