On 12/17/2011 10:13 AM, DRG wrote:
> On Dec 17, 2:31 pm, dpb<n...@non.net> wrote:
...[top posting repaired. Please don't; hard conversation follow makes]...
...
>>> for S = 9000:1:10000
>>> for R = 7000:1:8500
>>
>>> but I run into problems here, as
>>
>>> E(S,R) will give an error message, as indeed it should. Each answer
>>> for E is a 1x800 array and obviously calling E(S,R) makes no sense but
>>> I have no idea how to call it. Does anyone know how I should, so for
>>> each value of S and R I can get a 1 x 800 value ?
>>
>> ...
>>
>> Either run the loops over 1:N, 1:M and create the value inside the loops
>> instead of using the indices or vice versa; use the value as loops but
>> create the indices. I'd do the former, probably...
>>
>> Preallocate E, of course for speed...
>>
>> E=zeros(1001,1501);
>> S=9000;
>> for s=1:N
>> R=7000;
>> for r=1:M
>> E(s,r)=yourfunction(S,R);
>> %anything else inside r loop here
>> R=R+1;
>> end
>> %anything else inside s loop here
>> S=S+1;
>> end
...
> Thanks for the reply, but I'm not sure what you mean ? Let's say the
> code looks like this;
I mean exactly what I wrote... :)
> for s = 9000:1:10000
> for r = 7000:1:8500
...
> Please do guide me on this...
Did above. Don't run the loop over s,r; use 1:length(9000:10000) and
1:length(7000:8500) instead for the loops themselves and compute the
argument values for the function separately.
Run the following sample code and generalize to your situation of exact
numbers...
E=zeros(3,5);
S=9000;
for s=1:3
R=7000;
for r=1:5
E{s,r}=func(S,R);
R=R+1;
end
S=S+1;
end
function ret=func(x,y)
ret=rand(5,1)*(x/y);
This returns a cell array E each cell of which for each combination of S
and R column vector of length 5 (the results of the function func).
Plug in your values and function and voila!
If that's not the result you're shooting for you need a better/different
problem description.
Read on cell arrays in the help documentation.

