From: sr on
Hi Friends,

I have a problem with Matrix operation. I have a matrix of dimension 21rows by 386 columns. I want to make a new matrix with first 10 elements of first row as 1st row of my new matrix, second 10 elements of first row as 2nd row of my new matrix,.......38 rows and last row has only six elements. Same thing i have to repeat for all the 21 rows.

In other words, i need my output matrix in 10f10.3 format. I need this format as input to my fortran program.

Is there a command to do this job? Please help me. I need to repeat this step again and again for different matrices, and it takes for ever to do it manually.

I tried with different commands repmat, reshape, fprintf, sprintf, textscan, textread, fid, fgetl, ....but was not successful.

Thanking you in anticipation

cheers
From: dpb on
sr wrote:
> ... I have a matrix of dimension
> 21 rows by 386 columns. I want to make a new matrix with first 10
> elements of first row as 1st row of my new matrix, second 10 elements of
> first row as 2nd row of my new matrix,.......38 rows and last row has
> only six elements. Same thing i have to repeat for all the 21 rows.
>
> In other words, i need my output matrix in 10f10.3 format. I need this
> format as input to my fortran program.
>
> Is there a command to do this job? ...

Of course... :)

sprintf() is your friend here. Not as simple as the Fortran FORMAT but
doable...

sprintf([repmat('%10.3f',1,10) '\n'], x')

Pull out the [repmat('%10.3f',1,10) '\n'] part and past it at the
command line to see what it does and all should become clear...

--
From: dpb on
dpb wrote:
> sr wrote:
>> ... I have a matrix of dimension 21 rows by 386 columns. I want to
>> make a new matrix with first 10 elements of first row as 1st row of my
>> new matrix, second 10 elements of first row as 2nd row of my new
>> matrix,.......38 rows and last row has only six elements. Same thing i
>> have to repeat for all the 21 rows.
>>
>> In other words, i need my output matrix in 10f10.3 format. I need this
>> format as input to my fortran program.
....

> sprintf([repmat('%10.3f',1,10) '\n'], x')
>
> Pull out the [repmat('%10.3f',1,10) '\n'] part and past it at the
> command line to see what it does and all should become clear...

Oh, two comments...first, note the "'" transpose operator to output the
array in row-major order; otherwise it would be natural storage order of
column-wise, and secondly, you may need to add a final linefeed
character to terminate the final line, depending on the Fortran READ

--
From: sr on
Thank you very much for your help. It is working. I used for loop to complete it.

Thanks a lot.

dpb <none(a)non.net> wrote in message <hu094c$so6$1(a)news.eternal-september.org>...
> dpb wrote:
> > sr wrote:
> >> ... I have a matrix of dimension 21 rows by 386 columns. I want to
> >> make a new matrix with first 10 elements of first row as 1st row of my
> >> new matrix, second 10 elements of first row as 2nd row of my new
> >> matrix,.......38 rows and last row has only six elements. Same thing i
> >> have to repeat for all the 21 rows.
> >>
> >> In other words, i need my output matrix in 10f10.3 format. I need this
> >> format as input to my fortran program.
> ...
>
> > sprintf([repmat('%10.3f',1,10) '\n'], x')
> >
> > Pull out the [repmat('%10.3f',1,10) '\n'] part and past it at the
> > command line to see what it does and all should become clear...
>
> Oh, two comments...first, note the "'" transpose operator to output the
> array in row-major order; otherwise it would be natural storage order of
> column-wise, and secondly, you may need to add a final linefeed
> character to terminate the final line, depending on the Fortran READ
>
> --
From: dpb on
sr wrote:
> Thank you very much for your help. It is working. I used for loop to
> complete it.
....

How so come for to need a for loop????

--