matrices with different size [message #42151] |
Thu, 13 January 2005 08:21  |
ikverveelmijdood
Messages: 1 Registered: January 2005
|
Junior Member |
|
|
Hi,
my problem is the following: I have a dataset with a strong sinusoidal
component. However, its period and height are not constant. What I
exactly want is to split-up the data in different parts, and put them
into a matrix. Is this possible in IDL (and how?) to generate a
matrix, filled with vectors that have a different length? I know that
in Matlab "cell arrays" can be used.
Best regards,
Veerle
|
|
|
|
Re: Matrices [message #82878 is a reply to message #42151] |
Mon, 21 January 2013 12:06  |
Jeremy Bailin
Messages: 618 Registered: April 2008
|
Senior Member |
|
|
On 1/21/13 11:39 AM, fd_luni@mail.com wrote:
> Τη Δευτέρα, 21 Ιανουαρίου 2013 5:21:13 μ.μ. UTC+2, ο χρήστης Matthew Argall έγραψε:
>>> myNbyFour [:,0] = [1, 2, 3, 4]
>>
>>
>>
>> Sorry, this should be
>>
>>
>>
>> myNbyFour[0,*] = [1, 2, 3, 4]
>
> Thank you very much for your answers. Maybe I didn't explain very well what I actually wanna do before. Let's say I have four arrays A,B,C,D and E with 100 elements each. Now, I want to create an array which includes the elements of A,B,C and D (100 by 4 matrix).In other words, I want to write the four arrays A,B,C,D into 1 matrix,and a matrix which includes only the elements of E (vertically) so 100 by 1 matrix.
>
IDL> ABCD = [[A], [B], [C], [D]]
IDL> help, ABCD
<Expression> FLOAT = Array[100, 4]
IDL> Ecolumn = reform(E, n_elements(E), 1)
IDL> help, Ecolumn
ECOLUMN FLOAT = Array[100, 1]
Of course, Ecolumn will lose the trailing single dimension if you do
anything with it... but many (but not all!) things you might think of
doing with it won't care.
-Jeremy.
|
|
|
Re: Matrices [message #82883 is a reply to message #42151] |
Mon, 21 January 2013 09:55  |
fd_luni
Messages: 66 Registered: January 2013
|
Member |
|
|
Thank you very much for your answers. Maybe I didn't explain very well what I actually wanna do before. Let's say I have four arrays A,B,C,D and E with 100 elements each. Now, I want to create an array which includes the elements of A,B,C and D (100 by 4 matrix).In other words, I want to write the four arrays A,B,C,D into 1 matrix,and a matrix which includes only the elements of E(vertically) so 100 by 1 matrix.
P.S. an N by 4 matrix has N rows and 4 colunmns!!
|
|
|
Re: Matrices [message #82884 is a reply to message #42151] |
Mon, 21 January 2013 09:39  |
fd_luni
Messages: 66 Registered: January 2013
|
Member |
|
|
Τη Δευτέρα, 21 Ιανουαρίου 2013 5:21:13 μ.μ. UTC+2, ο χρήστης Matthew Argall έγραψε:
>> myNbyFour [:,0] = [1, 2, 3, 4]
>
>
>
> Sorry, this should be
>
>
>
> myNbyFour[0,*] = [1, 2, 3, 4]
Thank you very much for your answers. Maybe I didn't explain very well what I actually wanna do before. Let's say I have four arrays A,B,C,D and E with 100 elements each. Now, I want to create an array which includes the elements of A,B,C and D (100 by 4 matrix).In other words, I want to write the four arrays A,B,C,D into 1 matrix,and a matrix which includes only the elements of E (vertically) so 100 by 1 matrix.
|
|
|
Re: Matrices [message #82885 is a reply to message #42151] |
Mon, 21 January 2013 07:21  |
Matthew Argall
Messages: 286 Registered: October 2011
|
Senior Member |
|
|
> myNbyFour [:,0] = [1, 2, 3, 4]
Sorry, this should be
myNbyFour[0,*] = [1, 2, 3, 4]
|
|
|
Re: Matrices [message #82886 is a reply to message #42151] |
Mon, 21 January 2013 07:20  |
Matthew Argall
Messages: 286 Registered: October 2011
|
Senior Member |
|
|
> I want to create an N by 4 (Nx4)matrix and an N by 1 (Nx1)matrix with my own elements. Does anyone know how to do it?
Helder's first example is good, but also, look into
Look into the lonarr(), intarr(), fltarr(), dblarr(), etc. functions in addition to make_array(). If you want a floating point array
N = 10
myNbyFour = fltarr(N, 4)
myNbyOne = fltarr(N, 1)
Then you can assign values to each element like
myNbyFour[0,0] = 5
or
myNbyFour [:,0] = [1, 2, 3, 4]
etc
|
|
|
Re: Matrices [message #82887 is a reply to message #42151] |
Mon, 21 January 2013 06:48  |
Helder Marchetto
Messages: 520 Registered: November 2011
|
Senior Member |
|
|
On Monday, January 21, 2013 3:32:42 PM UTC+1, fd_...@mail.com wrote:
> Hello!
>
>
>
> I just start using IDL and I have one simple question about matrices.
>
>
>
> I want to create an N by 4 (Nx4)matrix and an N by 1 (Nx1)matrix with my own elements. Does anyone know how to do it?
Hi,
this is not normally the way people make things, however here is a command line option:
MyFiveByFourMatrix = [[0,4,8,12,16],[1,5,9,13,17],[2,6,10,14,18],[3,7,11,15,19]]
To check, just type:
help, MyFiveByFourMatrix
But generally you would like to use something like:
N=10
MyFiveByFourMatrix = Make_array(N,4,/INTEGER) ; Makes a 10x4 matrix
If you want to do a Nx1 matrix, use either:
N_by_One_Matrix = [0,1,2,3,4,5]
or
N_by_One_Matrix = Make_array(N,1,/INTEGER)
The above actually generates an array of N elements. If you really want a Nx1, then you should do the following:
N_by_One_Matrix = reform([0,1,2,3,4,5], 6,1)
or
N_by_One_Matrix = reform(Make_array(N,/INTEGER),N,1)
Hope it helps.
Cheers,
Helder
|
|
|