[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Function in a Loop output problem
From: |
Fotios Kasolis |
Subject: |
Re: Function in a Loop output problem |
Date: |
Wed, 8 Sep 2010 17:04:37 +0200 |
On Sep 8, 2010, at 4:48 PM, bpabbott wrote:
> On 08 Sep, 2010,at 10:42 AM, dirac <address@hidden> wrote:
>
>>
>> Hi again everyone,
>>
>> I have yet another problem that I have been stuck on for a few hours now: I
>> have a loop that calls a function whose output is two vectors.
>>
>> for i=1:20
>> [a,b]=function(variables)
>> end
>>
>> I want to use the data [a,b] once the loop has finished and the only way I
>> thought of this is to make a matrix whose columns are the vectors i.e add a
>> new column to two matrices wach time the loop goes around...if that makes
>> sense. a and b are equal in length but different for each iteration of the
>> loop if that makes sense...
>>
>> Is there a way to do that? I thought of having two pre defined NaN matrix
>> with 20 columns so that I can replace each column with a and b each
>> iteration..
>>
>> Thanks in advance
>>
>> Martin
>
>
> I assume "a" and "b" are scalars?
>
> a = b = zeros (1, 20);
> for i = 1:20
> [a(i), b(i)] = function (variables);
> endfor
>
> Ben
>
>
> _______________________________________________
> Help-octave mailing list
> address@hidden
> https://www-old.cae.wisc.edu/mailman/listinfo/help-octave
Something like that ??
A = zeros (max_size_needed_1, max_size_needed_2);
B = zeros (max_size_needed_3, max_size_needed_4);
for i = 1:20
[a, b] = function (args);
size_a = length (a);
size_b = length (b);
A (i, 1:size_a) = a;
B (i, 1:size_a) = b;
end
/Fotis