From: omegayen on 27 Apr 2010 15:30 Walter Roberson <roberson(a)hushmail.com> wrote in message <hlkgv6$hbr$1(a)canopus.cc.umanitoba.ca>... > omegayen wrote: > > > adata=adata_real+1i*adata_imag; > > You could probably do that more efficiently with > > adata = complex(adata_real, adata_imag); > > > I wouldn't have bothered to use two different files, myself, but looking > around the documentation and trying some tests, I don't see any plausible > alternative to separating out the real and imaginary parts the way you have > done. I *expected* that I would find some option in fwrite that would write > out both parts of the complex in a single operation, but that option does not > seem to be present. > > I also expected to be able to typecast complex into bytes, but that isn't > allowed either, probably because the two parts of complex are actually stored > separately, whereas typecast would normally just have to change the type > information without touching the data section. Thanks walter. Now I have one more question which I know may seem trivial. But how do I open this file I am writing (see post #7 above) in another platform such as Maple or Excel? It works as is in Matlab...
From: James Tursa on 27 Apr 2010 16:13 Walter Roberson <roberson(a)hushmail.com> wrote in message <hlkgv6$hbr$1(a)canopus.cc.umanitoba.ca>... > > I also expected to be able to typecast complex into bytes, but that isn't > allowed either, probably because the two parts of complex are actually stored > separately, whereas typecast would normally just have to change the type > information without touching the data section. FYI, although the MATLAB version of typecast does not allow the complex parts as you have noted, my version of typecast on the FEX does allow this extension. Also, the MATLAB version of typecast actually copies the data to the new class variable, which as you have noted is pretty much a waste of time and resources. My version of typecast, however, creates a shared data copy of the original with changed header information. This is much faster and can become particularly important if you are working with large arrays. You can find my version of typecast here: http://www.mathworks.com/matlabcentral/fileexchange/17476-typecast-c-mex-function I will note that I just read the comments in my file and they are incorrect as to the complex stuff. The comments in my file state that the input must be non-complex just like the MATLAB typecast function. This is not true ... you can in fact use complex inputs with my version of typecast. I will have to update these comments and upload new files. James Tursa
From: omegayen on 24 May 2010 13:00 "James Tursa" <aclassyguy_with_a_k_not_a_c(a)hotmail.com> wrote in message <hr7gge$i14$1(a)fred.mathworks.com>... > Walter Roberson <roberson(a)hushmail.com> wrote in message <hlkgv6$hbr$1(a)canopus.cc.umanitoba.ca>... > > > > I also expected to be able to typecast complex into bytes, but that isn't > > allowed either, probably because the two parts of complex are actually stored > > separately, whereas typecast would normally just have to change the type > > information without touching the data section. > > FYI, although the MATLAB version of typecast does not allow the complex parts as you have noted, my version of typecast on the FEX does allow this extension. Also, the MATLAB version of typecast actually copies the data to the new class variable, which as you have noted is pretty much a waste of time and resources. My version of typecast, however, creates a shared data copy of the original with changed header information. This is much faster and can become particularly important if you are working with large arrays. You can find my version of typecast here: > > http://www.mathworks.com/matlabcentral/fileexchange/17476-typecast-c-mex-function > > I will note that I just read the comments in my file and they are incorrect as to the complex stuff. The comments in my file state that the input must be non-complex just like the MATLAB typecast function. This is not true ... you can in fact use complex inputs with my version of typecast. I will have to update these comments and upload new files. > > James Tursa Just bumping this back up because still unsure... Now I have one more question which I know may seem trivial. How do I open this text file I am writing (see post #7 above) in another platform such as Maple or Excel? It works as is in Matlab...
From: Walter Roberson on 24 May 2010 13:20 omegayen wrote:. > > Now I have one more question which I know may seem trivial. > How do I open this text file I am writing (see post #7 above) in another > platform such as Maple or Excel? > It works as is in Matlab... If you are working with the code in this thread, then you do not have a text file, you have a binary file. fwrite() writes binary data, and fopen() only creates text files if you give it the 't' flag, as in fopen('FileName.txt', 'wt') If you want to read a binary file into Maple, you can use readbytes() in Maple. You should examine the documentation for that to see the best way to do that. http://www.maplesoft.com/support/help/Maple/view.aspx?path=readbytes
From: omegayen on 24 May 2010 14:32
Walter Roberson <roberson(a)hushmail.com> wrote in message <jzyKn.21352$mi.7665(a)newsfe01.iad>... > omegayen wrote:. > > > > Now I have one more question which I know may seem trivial. > > How do I open this text file I am writing (see post #7 above) in another > > platform such as Maple or Excel? > > It works as is in Matlab... > > If you are working with the code in this thread, then you do not have a > text file, you have a binary file. fwrite() writes binary data, and > fopen() only creates text files if you give it the 't' flag, as in > > fopen('FileName.txt', 'wt') > > If you want to read a binary file into Maple, you can use readbytes() in > Maple. You should examine the documentation for that to see the best way > to do that. > > http://www.maplesoft.com/support/help/Maple/view.aspx?path=readbytes I see thanks for clarifying, so if I want MATLAB to generate text files I would have to do something such as fid = fopen('FileName.txt','wt'); fprintf(fid,'%16.16f\n',myvariable); fclose(fid); so if my variable is double, what is the appropriate method for the fprintf if I want to keep all the digits but not tack on any extras as well... ? thanks |