help-octave
[Top][All Lists]
Advanced

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

Re: Condensing indices in a matrix


From: Kai Torben Ohlhus
Subject: Re: Condensing indices in a matrix
Date: Tue, 8 Dec 2020 15:20:17 +0900
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.5.0

On 12/8/20 6:10 AM, Brett Green wrote:
Is it possible to construct a matrix of the following form without for loops?

Start with a multidimensional array
M( T1 , n1 , m1 , T2 , n2 , m2 )
where we have the same size in the T1 and T2 dimensions, the n1 and n2 dimensions, and the m1 and m2 dimensions.

Then, for each n and m, set
M( 1 , n , m , 2 , n , m ) = a;
M( 2 , n , m , 1 , n+1 , m ) = b;
M( 2 , n , m , 1 , n , m+1 ) = c;
for some numbers a, b and c. I can do this with e.g.
M( 1 , : , : , 2 , : , : ) = a;
so this is not a problem.

Then condense the multidimensional array to a 2D array
M( u(T1,n1,m1) , u(T2,n2,m2) )
where u is some function that condenses the indices from tuples of 3 to single indices. The function u can be anything that condenses our indices this way, though it'd be especially nice if I could define it myself.

I am familiar with using reshape to condense all indices. Is there also a way to condense only certain indices? Or, is there another way to construct this matrix besides reshaping a multidimensional array?

- Brett Green



Was it possible to send some minimal working example how array M is created? For u(x,y,z), maybe `sub2ind` [1] can be helpful.

HTH,
Kai

[1] https://octave.org/doc/v6.1.0/Advanced-Indexing.html




reply via email to

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