From: Sumeet T on

Hi,

I am facing a trouble while concatenating in a loop. Here is a problem:

I have matrix B1, B2, B3, B4.....,B20 (each matrix has different number of rows but have same number of columns i.e. 3) and on each matrix I perform a certain operation. At the end of the operation I write the data to a txt file and clear everything else.

To process everything at one go, I wish to have a loop so that the code reads each matrix performs the operation, and moves to the next matrix. But I cant figure out the way to code. I have the following in my mind but do not know how to move forward:

for j=1:1:20
m= strcat('B', j);


..... Perform mathematical operation on matrix m
.....

end

After concatenation of the B with j, m=Bj (j has a value like 1 or 2..or...), but m is not the same as Bj matrix. Can someone please help me figure out the correct solution to this problem. I very much appreciate your assistance.

Thanks so much.
From: Steven_Lord on


"Sumeet T" <sumeettrehan(a)gmail.com> wrote in message
news:i4185r$nat$1(a)fred.mathworks.com...
>
> Hi,
>
> I am facing a trouble while concatenating in a loop. Here is a problem:
>
> I have matrix B1, B2, B3, B4.....,B20 (each matrix has different number of
> rows but have same number of columns i.e. 3)

Don't do this! See Q4.6 in the newsgroup FAQ for alternatives.

--
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: Jan Simon on
Dear Sumeet,

> I have matrix B1, B2, B3, B4.....,B20

This structure yields to the difficulties you have. It is recommended not to mix the data structure and the data itself. You would not append the time-table to the name of a pupil, also there could be some advantages in doing so.

Better: Collect the arrays in a cell array: B{1}, B{2}, ...
Then the final concatenation is easy:
CatB = cat(1, B{:});

Kind regards, Jan
From: Sumeet T on

Thanks Steve and Jan! That was very helpful.


"Jan Simon" <matlab.THIS_YEAR(a)nMINUSsimon.de> wrote in message <i41tjc$bav$1(a)fred.mathworks.com>...
> Dear Sumeet,
>
> > I have matrix B1, B2, B3, B4.....,B20
>
> This structure yields to the difficulties you have. It is recommended not to mix the data structure and the data itself. You would not append the time-table to the name of a pupil, also there could be some advantages in doing so.
>
> Better: Collect the arrays in a cell array: B{1}, B{2}, ...
> Then the final concatenation is easy:
> CatB = cat(1, B{:});
>
> Kind regards, Jan