Hello,
With MATLAB, does anyone know how to write a multi-dimensional matrix into an text file
By multi-dimensional, I mean C(:,:,M,h,bottom_top) where the first : is for all latitudes and the 2nd : is for all longitude, M
is for day, h is for hour, bottom_top is vertical levels
I tried the following with no success:
text_name = 'lightning.txt'
dlmwrite(text_name, C(:,:,M,h,bottom_top),'\t')
If there are 2 M dimensions, 4 h dimensions, and 4 bottom_top dimensions means that he text file should contain 32 matrices (arrays) with a line skipped in between each one.
Thanks
Jonathan
|
|
0
|
|
|
|
Reply
|
Jonathan
|
1/17/2011 7:59:05 PM |
|
"Jonathan W Smith" wrote in message <ih2729$e91$1@fred.mathworks.com>...
> Hello,
>
> With MATLAB, does anyone know how to write a multi-dimensional matrix into an text file
>
> By multi-dimensional, I mean C(:,:,M,h,bottom_top) where the first : is for all latitudes and the 2nd : is for all longitude, M
> is for day, h is for hour, bottom_top is vertical levels
> I tried the following with no success:
>
>
> text_name = 'lightning.txt'
>
> dlmwrite(text_name, C(:,:,M,h,bottom_top),'\t')
>
> If there are 2 M dimensions, 4 h dimensions, and 4 bottom_top dimensions means that he text file should contain 32 matrices (arrays) with a line skipped in between each one.
>
> Thanks
> Jonathan
Write and read it as binary with:
doc fopen
doc fwrite
doc fread
|
|
0
|
|
|
|
Reply
|
Sean
|
1/17/2011 8:15:21 PM
|
|
On 11-01-17 01:59 PM, Jonathan W Smith wrote:
> With MATLAB, does anyone know how to write a multi-dimensional matrix into an
> text file
There is no method provided by Mathworks; you will have to program it yourself.
> If there are 2 M dimensions, 4 h dimensions, and 4 bottom_top dimensions
> means that he text file should contain 32 matrices (arrays) with a line
> skipped in between each one.
There is no Mathworks provided support for reading such files as
multi-dimensional arrays; you would have to program the reading yourself.
> By multi-dimensional, I mean C(:,:,M,h,bottom_top)
If I were designing the output format, I would want a break or some kind of
indicator each time the dimension changed, as otherwise the output would not
be distinguishable from that for a matrix of size C(:,:,M*h*bottom_top)
|
|
0
|
|
|
|
Reply
|
Think
|
1/17/2011 8:19:01 PM
|
|
"Think two, count blue." <roberson@hushmail.com> wrote in message <ih28aj$cdm$1@nrc-news.nrc.ca>...
> On 11-01-17 01:59 PM, Jonathan W Smith wrote:
>
> > With MATLAB, does anyone know how to write a multi-dimensional matrix into an
> > text file
>
> There is no method provided by Mathworks; you will have to program it yourself.
>
> > If there are 2 M dimensions, 4 h dimensions, and 4 bottom_top dimensions
> > means that he text file should contain 32 matrices (arrays) with a line
> > skipped in between each one.
>
> There is no Mathworks provided support for reading such files as
> multi-dimensional arrays; you would have to program the reading yourself.
>
> > By multi-dimensional, I mean C(:,:,M,h,bottom_top)
>
> If I were designing the output format, I would want a break or some kind of
> indicator each time the dimension changed, as otherwise the output would not
> be distinguishable from that for a matrix of size C(:,:,M*h*bottom_top)
I just created these multi-dimensional arrays in matlab. It seems like they may have to be read in a dimension at a time. Is that what you saying above?
|
|
0
|
|
|
|
Reply
|
Jonathan
|
1/17/2011 9:10:21 PM
|
|
"Jonathan W Smith" wrote in message <ih2b7t$634$1@fred.mathworks.com>...
> "Think two, count blue." <roberson@hushmail.com> wrote in message <ih28aj$cdm$1@nrc-news.nrc.ca>...
> > On 11-01-17 01:59 PM, Jonathan W Smith wrote:
> >
> > > With MATLAB, does anyone know how to write a multi-dimensional matrix into an
> > > text file
> >
> > There is no method provided by Mathworks; you will have to program it yourself.
> >
> > > If there are 2 M dimensions, 4 h dimensions, and 4 bottom_top dimensions
> > > means that he text file should contain 32 matrices (arrays) with a line
> > > skipped in between each one.
> >
> > There is no Mathworks provided support for reading such files as
> > multi-dimensional arrays; you would have to program the reading yourself.
> >
> > > By multi-dimensional, I mean C(:,:,M,h,bottom_top)
> >
> > If I were designing the output format, I would want a break or some kind of
> > indicator each time the dimension changed, as otherwise the output would not
> > be distinguishable from that for a matrix of size C(:,:,M*h*bottom_top)
>
>
>
> I just created these multi-dimensional arrays in matlab. It seems like they may have to be read in a dimension at a time. Is that what you saying above?
You just have to record the size, it's an input argument to FREAD. Or you RESHAPE after reading it in as a vector.
|
|
0
|
|
|
|
Reply
|
Sean
|
1/17/2011 9:19:05 PM
|
|
"Sean de " <sean.dewolski@nospamplease.umit.maine.edu> wrote in message <ih2bo9$9gl$1@fred.mathworks.com>...
> "Jonathan W Smith" wrote in message <ih2b7t$634$1@fred.mathworks.com>...
> > "Think two, count blue." <roberson@hushmail.com> wrote in message <ih28aj$cdm$1@nrc-news.nrc.ca>...
> > > On 11-01-17 01:59 PM, Jonathan W Smith wrote:
> > >
> > > > With MATLAB, does anyone know how to write a multi-dimensional matrix into an
> > > > text file
> > >
> > > There is no method provided by Mathworks; you will have to program it yourself.
> > >
> > > > If there are 2 M dimensions, 4 h dimensions, and 4 bottom_top dimensions
> > > > means that he text file should contain 32 matrices (arrays) with a line
> > > > skipped in between each one.
> > >
> > > There is no Mathworks provided support for reading such files as
> > > multi-dimensional arrays; you would have to program the reading yourself.
> > >
> > > > By multi-dimensional, I mean C(:,:,M,h,bottom_top)
> > >
> > > If I were designing the output format, I would want a break or some kind of
> > > indicator each time the dimension changed, as otherwise the output would not
> > > be distinguishable from that for a matrix of size C(:,:,M*h*bottom_top)
> >
> >
> >
> > I just created these multi-dimensional arrays in matlab. It seems like they may have to be read in a dimension at a time. Is that what you saying above?
>
> You just have to record the size, it's an input argument to FREAD. Or you RESHAPE after reading it in as a vector.
Hello again,
I was able to get those multi-dimensional matrices written to files by using the following commands:
fid = fopen('lightning.txt', 'w');
fprintf(fid,'%8.4f %8.4f %8.4f %8.4f\n',C)
fclose(fid);
However the elements in each dimension have the incorrect matrix address:.
If a dimension of the multi-dimensional matrix takes this form:
C(:,:,1)
0 3 0 7
0 6 2 9
0 0 1 4
0 0 0 0
It prints to the text file incorrectly in this form:
0 0 0 0
4 1 0 0
9 2 6 0
7 0 3 0
I tried to do a rot90(C,2), but rot90 can only be used on 2D matrices. See below
???Error using ==> rot90
A must be a 2-D matrix.
Error in ==> xlat_xlon_test at 70
fprintf(fid,'1382753164843508800000000000000000
Any thoughts????
Jonathan
|
|
0
|
|
|
|
Reply
|
Jonathan
|
1/18/2011 12:45:24 PM
|
|
|
5 Replies
539 Views
(page loaded in 0.826 seconds)
Similiar Articles: write multidimensional matrix to text file - comp.soft-sys.matlab ...Hello, With MATLAB, does anyone know how to write a multi-dimensional matrix into an text file By multi-dimensional, I mean C(:,:,M,h,bottom_top... Write results to text file??? - comp.soft-sys.matlabwrite multidimensional matrix to text file - comp.soft-sys.matlab ... Hello, With MATLAB, does anyone know how to write a multi-dimensional matrix into an text file ... write a cell array to text file.. - comp.soft-sys.matlab ...write multidimensional matrix to text file - comp.soft-sys.matlab ..... With MATLAB, does anyone know how to write a multi-dimensional matrix into an text file ... write linebreaks into text file - comp.soft-sys.matlabwrite multidimensional matrix to text file - comp.soft-sys.matlab ... write linebreaks into text file - comp.soft-sys.matlab write multidimensional matrix to text file ... Write sequence text files within a loop - comp.soft-sys.matlab ...write multidimensional matrix to text file - comp.soft-sys.matlab ... Write sequence text files within a loop - comp.soft-sys.matlab ... write multidimensional matrix to ... Reading/writing data to/from files into 2D array - comp.lang.vhdl ...write multidimensional matrix to text file - comp.soft-sys.matlab ..... writing data to netcdf file ... store it into a 2D matrix. I've been using fscanf to do so ... multidimensional matrix multiplication - comp.soft-sys.matlab ...write multidimensional matrix to text file - comp.soft-sys.matlab ... multidimensional matrix multiplication - comp.soft-sys.matlab ... write multidimensional matrix to ... How to get matrix output by using parfor loop - comp.soft-sys ...write multidimensional matrix to text file - comp.soft-sys.matlab ..... top) > > > > If I were designing the output ... Write sequence text files within a loop - comp ... resizing static text - comp.soft-sys.matlabText-to-speech in MATLAB - comp.soft-sys.matlab However the elements in each dimension have the incorrect matrix address:. ... write multidimensional matrix to text file ... Selecting elements of a multidimensional matrix - comp.soft-sys ...write multidimensional matrix to text file - comp.soft-sys.matlab ..... 4f %8.4f\n',C) fclose(fid); However the elements in each dimension have the incorrect matrix ... write multidimensional matrix to text file - comp.soft-sys.matlab ...Hello, With MATLAB, does anyone know how to write a multi-dimensional matrix into an text file By multi-dimensional, I mean C(:,:,M,h,bottom_top... write multidimensional matrix to text file - Newsreader - MATLAB ...Hello, With MATLAB, does anyone know how to write a multi-dimensional matrix into an text file By multi-dimensional, I mean C(:,:,M,h,bottom_top) where the first : is ... 7/20/2012 5:02:08 PM
|