help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Issue with the variable after exiting for loop


From: Brett Green
Subject: Re: Issue with the variable after exiting for loop
Date: Thu, 28 May 2020 18:35:34 -0400



On Thu, May 28, 2020 at 6:30 PM Przemek Klosowski <przemek.klosowski@nist.gov> wrote:

Just for clarification, there are two ways to deal with it: either start at the end and work backwards (for i=sizeX:-1:1 ; for j=sizeY:-1:0 ; abc_p(i,j)=...; end; end    or simply preallocate the last element   abc_p(sizeX,sizeY)=1 before the loop (it will presumably be overwritten with the correct value later, but the array will be preallocated to full size).


Thank you suggesting that; it never hurts to have multiple solutions. I think I've done it both ways on some occasion or another, but usually I find it more natural just to do something like abc_p = zeros(sizeX,sizeY).

reply via email to

[Prev in Thread] Current Thread [Next in Thread]