On 4/16/2013 7:24 AM, k.vigneshwaran K wrote:
> Dear sir,
> l(i) value will change with respect to n no of times.
>
> l(i1)=0; l(i) =l; %THE INCREMENT OF l(i) is l
> l(i+1)=l+l;
>
> due to the every value of l(i),i want to retrieve the KR VALUES.
> example. if l(1)=l; then my KR=SOMETHING xx for i=1,
> at the same time i shall retrieve the forthcoming values of KR.
>
> here i is changing for every elements of i,and also due to the different
> value of L I should get KR VALUE.
>
> THE LOOP WHICH I MADE IT SHOWN TO YOU FOR YOUR REFERENCE SIR.
>
> K=4 CROSS 4 MATRIX
> l(i)=l
> for i=1:2
KR=l(i)*K;
> l(i)=l(i)+l;
> end
> for this loop matlab showing like below
>
> ??? Subscript indices must either be real positive integers or
> logicals.
>
>
> PLEASE GUIDE ME TO OBTAIN THE SOLUTON.
Your caplock key seems to get stuck on...check your keyboard.
A) 'i' and 'j' are builtin functions > sqrt(1) in Matlab so the first
line above is trying to reference and array by that value as an index.
Obviously this isn't kosher so that's the error message.
B) Matlab array indexing is 1based, not 0based so your first index
_MUST_ always be >0 (or >=1))(*).
Using the crystal ball, perhaps you meant something like
l(1)=l; % initialize a first location before starting a loop
for i=1:2
KR=l(i)*K;
l(i)=l(i)+l;
end
The above would have the result of KR successively becoming n*K where n
= 1, 2. The end result unless you do something else with it inside the
loop before the next iteration will be only KR=N*K where in you example
N=2 since you overwrite KR every pass.
The above result could be obtain simply by using the loop index instead
of the auxiliary variable 'l' as
for i=1:2
KR=i*K;
end
with the same end result, of course.
As Steven says, explain the end result w/o trying to write the code so
folks can try to get the underlying objective instead of trying to
decipher incorrect coding. Understanding that there's a language
barrier for most readers of cssm, bear with us as we try to interpret
but also work from your end to provide a precise definition of the
problem in a clear form not (or at least minimally) confounded by
programming issues.
(*) Ignoring for the moment the logical index which means something
quite entirely different than the absolute value of 0,1 but is positional.

