From: Vincent Seow on 7 Oct 2009 09:32 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 7 Oct 2009 10:44 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 7 Oct 2009 09:30 Try this: clear; clc A = [1 2 3; 4 5 6; 7 8 9]; for b = 1:5 A1(:,:,b) = b*[A] end
|
Pages: 1 Prev: Improving precision in fminunc Next: CREATING A TOOL BAR |