Re: Multidimensional arrays

new topic     » goto parent     » topic index » view thread      » older message » newer message

felix wrote:
> 
> 
>  Hello everybody!
> 
>  Me, being working for a lot of time with Matlab, I like and use array
>  (sequence) programming.
>  Euphoria would be an interesting solution for calculus and GUI mixed
>  software. However,
> a focused question:
>  It is planned to intoduce the following feature in euphoria (for
>  multidimensional
> sequences):
>  seq[:][2] to select the second column and seq[3][:] to select the third line
>  of a
> 2D sequence (and so on...)? It would be very interesting (for me)
> to have it ...
> 
I just use a function like this:

-- this functions assumes that you've 
-- got a 2-d table/matrix and there are the
-- same number of elements (columns) in each row 
function cx(sequence M, integer ci)
sequence c
	if ci < 0 then
		ci = length(M[1]) + ci + 1
	end if
	c = repeat(0,length(M))
	for i = 1 to length(c) do
		c[i] = M[i][ci]
	end for
	return c
end function

So cx(s,3) extracts column 3 of matrix s.  Works pretty fast.

To invert the rows & columns, use this:

global function rotate(sequence x)
sequence rotated
atom dim1, dim2

	if not length(x) then
		return x -- empty returns empty
	end if

	dim1 = length(x[1])
	dim2 = length(x)
	rotated = repeat(repeat(0,dim2),dim1)

	for i = 1 to dim1 do
		for j = 1 to dim2 do
			rotated[i][j] = x[j][i]
		end for
	end for

	return rotated

end function

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu