From: Vincent Seow on
Hi,

I have a matrix A which depends on a variable b as follows:

[A1] = b[A]

Now I want to vary b with some increments and store the matrix A1 for different values of b. The values inside [A] are constant. I wrote the following codes. It works but doesn't store the data for each value of b. I heard it can be done by introducing third dimension to the matrix, but not sure how to do it. Can someone help?

for b = 1:1:10
A1(:,:) = b[A]
end

Thanks in advanced.

Vincent
From: ImageAnalyst on
On Oct 7, 9:32 am, "Vincent Seow" <en...(a)hotmail.com> wrote:
> Hi,
>
> I have a matrix A which depends on a variable b as follows:
>
> [A1] = b[A]
>
> Now I want to vary b with some increments and store the matrix A1 for different values of b. The values inside [A] are constant. I wrote the following codes. It works but doesn't store the data for each value of b. I heard it can be done by introducing third dimension to the matrix, but not sure how to do it. Can someone help?
>
> for b = 1:1:10
>   A1(:,:) = b[A]
> end
>
> Thanks in advanced.
>
> Vincent

You can preallocate a 3D matrix for A1
[rows cols] = size(A);
A1 = zeros(rows, cols, 10); % Third dimension the the number of b
values you will use.
then do something like (untested)
plane = 1;
for b = bStartValue : bIncrement : bEndValue
A1(:,:,plane) = b*A;
plane = plane+1
end

OR just tack on b*A to the A1 array using the cat() function,
something like (untested)
A1=cat(3,A1, b*A)
From: Jorge on
Try this:

clear; clc
A = [1 2 3; 4 5 6; 7 8 9];
for b = 1:5
A1(:,:,b) = b*[A]
end