On 4/29/2013 8:25 AM, Eric wrote:
> dpb <none@non.net> wrote in message <klkfkl$bs7$1@speranza.aioe.org>...
>> On 4/28/2013 6:08 PM, Eric wrote:
>> > Hello.
>> >
>> > I require assistance in making a string of 1D outputs in the form of
>> x =
>> > [2 2 -4], x = [1 5 -6] ect. and add them to a matrix that appears as
>> such:
>> ...
>>
>>
>> doc vertcat
>>
...
> That is brilliant. This will be useful. For my particular issue though,
> I have an array, A, that updates with each loop, and I want to catch the
> data from each loop into a matrix of row length n, where n is the number
> of loops. It may be bad from a memory standpoint but since this isnt
> doing large calculations it will be fine for this particular
> application. I am just unsure of how to do it.
If it's a counted loop, preallocate and populate.
If it's not large you can afford to just grow it in place but if it's
uncounted but large then allocate a sizable chunk and reallocate if
needed if required. You can always truncate to size at at end if needed.
N=some_count_limit;
M=zeros(N,length(your_return_vector));
for i=1:N
M(i,:)=your_function(whatever);
end
or, look at
doc arrayfun % and friends
You may be able to write it and let the allocation and loops occur
behind the scenes depending on your function.
Many ways to skin the proverbial feline...
--
> dpb <none@non.net> wrote in message <klkfkl$bs7$1@speranza.aioe.org>...
>> On 4/28/2013 6:08 PM, Eric wrote:
>> > Hello.
>> >
>> > I require assistance in making a string of 1D outputs in the form of
>> x =
>> > [2 2 -4], x = [1 5 -6] ect. and add them to a matrix that appears as
>> such:
>> ...
>>
>>
>> doc vertcat
>>
...
> That is brilliant. This will be useful. For my particular issue though,
> I have an array, A, that updates with each loop, and I want to catch the
> data from each loop into a matrix of row length n, where n is the number
> of loops. It may be bad from a memory standpoint but since this isnt
> doing large calculations it will be fine for this particular
> application. I am just unsure of how to do it.
If it's a counted loop, preallocate and populate.
If it's not large you can afford to just grow it in place but if it's
uncounted but large then allocate a sizable chunk and reallocate if
needed if required. You can always truncate to size at at end if needed.
N=some_count_limit;
M=zeros(N,length(your_return_vector));
for i=1:N
M(i,:)=your_function(whatever);
end
or, look at
doc arrayfun % and friends
You may be able to write it and let the allocation and loops occur
behind the scenes depending on your function.
Many ways to skin the proverbial feline...
--