[Gambas-user] FW: Matrix resize
terco IDE
tercoide at ...67...
Tue Dec 10 00:17:16 CET 2013
I prefer the Jussi aproach, because a lot of code is already wrtitten with [row,col]
format and is easier to read.
I hope that works for Public arrays!
Thanks
Martin
> Subject: Re: [Gambas-user] Matrix resize
> To: mailing list for gambas users <gambas-user at lists.sourceforge.net>
> Message-ID:
> <CAFkCsL6RRAU9d2B7fMzsfjZyuji0HBa7Uk=E3wmOH=vVmxmErQ at ...627...>
> Content-Type: text/plain; charset=ISO-8859-1
>
> You can use arrays of array
>
>
> private MyArray as new Object[]
>
> Public sub _New()
> ResizeMyArray(MyArray,15,12)
> end
>
>
>
> Public sub ResizeMyArray(hMyArray as Object[], X as integer, y as integer)
>
> hMyArray.Resize(X)
>
> For i = 0 to hMyArray.max
> if hMyArray [i] then
> hMyArray[i].Resize(y)
> else
> hMyArray[i] = new Integer[Y]
> endif
> next
>
>
>
> For the call :
>
> value = MyArray[1][2]
>
>
> 2013/12/5 Jussi Lahtinen <jussi.lahtinen at ...626...>:
> > Unfortunately this is missing feature from Gambas. Maybe Benoit has reason
> > for it, I don't know.
> >
> > However here is code for resizing 2D arrays:
> >
> > Private Function Resize2DArray(hArray As Object, SizeX As Integer, SizeY As
> > Integer) As Object
> >
> > Dim hNewArray As Object = Object.New(Object.Type(hArray), [SizeX, SizeY])
> > Dim ii As Integer, jj As Integer
> >
> > For ii = 0 To Min(hNewArray.Bounds[0], hArray.Bounds[0]) - 1
> > For jj = 0 To Min(hNewArray.Bounds[1], hArray.Bounds[1]) - 1
> > hNewArray[ii, jj] = hArray[ii, jj]
> > Next
> > Next
> >
> > Return hNewArray
> >
> > End
> >
> >
> > And here is how to use it:
> >
> > Dim iMyArray As New Integer[5, 5]
> >
> > iMyArray = Resize2DArray(iMyArray, 10, 10)
> >
> >
> > As it's not native method, it's not that fast, but fortunately Gambas is
> > *very* often fast enough!
> >
> >
> > Jussi
> >
> >
> >
> > On Thu, Dec 5, 2013 at 2:20 PM, terco IDE <tercoide at ...67...> wrote:
> >
> >> First of everything: BIG thanks to Benoit for creating Gambas!
> >>
> >> Is there any workaround for resizing matrices?
> >>
> >> rigth now, I'm using this code
> >>
> >> notMatrix.Resize(100*200) ' 100 rows, 200 cols
> >>
> >> ' get element [row,col]
> >>
> >> x = notMatrix[col + row*200]
> >>
> >> , and on a big program, code get's really dirty
> >>
> >>
> >> Thanks!
> >>
> >>
> >> Saludos
> >> Martin
> >>
> >>
More information about the User
mailing list