I am trying to write a file with both binary and ASCII data.
I managed to write my binary data with below codes:-
fid = fopen('CEOS.mat', 'wb');
value = 555
Write = typecast(uint16(value),'uint16');
b = fwrite(fid, Write, 'uint16');
value = 10
Write = typecast(uint8(value),'uint8');
b = fwrite(fid, Write, 'uint8');
fclose(fid)
I wanted to add in ASCII data, how can I write into the same file? can I use fwrite function too?
HELP!
|
|
0
|
|
|
|
Reply
|
Darlling5147
|
11/24/2010 7:52:05 AM |
|
"Darlling5147 Sew" <haha_1984@yahoo.com> wrote in message <icig74$52t$1@fred.mathworks.com>...
> I am trying to write a file with both binary and ASCII data.
>
> I managed to write my binary data with below codes:-
>
> fid = fopen('CEOS.mat', 'wb');
>
> value = 555
> Write = typecast(uint16(value),'uint16');
> b = fwrite(fid, Write, 'uint16');
>
> value = 10
> Write = typecast(uint8(value),'uint8');
> b = fwrite(fid, Write, 'uint8');
>
> fclose(fid)
>
>
> I wanted to add in ASCII data, how can I write into the same file? can I use fwrite function too?
>
> HELP!
I am not sure what you try to achieve.
Maybe this is what you need:
value = 'abcdefgh' ;
Write = cast(value,'uint8');
b = fwrite(fid, Write, 'uint8');
Hope this helps,
Han
|
|
0
|
|
|
|
Reply
|
Han
|
11/24/2010 11:32:10 AM
|
|
"Darlling5147 Sew" <haha_1984@yahoo.com> wrote in message <icig74$52t$1@fred.mathworks.com>...
> I am trying to write a file with both binary and ASCII data.
>
> I managed to write my binary data with below codes:-
>
> fid = fopen('CEOS.mat', 'wb');
>
> value = 555
> Write = typecast(uint16(value),'uint16');
> b = fwrite(fid, Write, 'uint16');
>
> value = 10
> Write = typecast(uint8(value),'uint8');
> b = fwrite(fid, Write, 'uint8');
>
> fclose(fid)
>
>
> I wanted to add in ASCII data, how can I write into the same file? can I use fwrite function too?
>
> HELP!
You can use fprintf to write to the same file.
|
|
0
|
|
|
|
Reply
|
Cris
|
11/24/2010 1:54:04 PM
|
|
On 24/11/10 1:52 AM, Darlling5147 Sew wrote:
> I am trying to write a file with both binary and ASCII data.
> I managed to write my binary data with below codes:-
>
> fid = fopen('CEOS.mat', 'wb');
>
> value = 555
> Write = typecast(uint16(value),'uint16');
> b = fwrite(fid, Write, 'uint16');
>
> value = 10
> Write = typecast(uint8(value),'uint8');
> b = fwrite(fid, Write, 'uint8');
>
> fclose(fid)
>
>
> I wanted to add in ASCII data, how can I write into the same file? can I
> use fwrite function too?
fwrite(fid, 'They weep not, and neither do they toil');
The main difference between a binary file and a text file is in the
handling of line terminators. With a binary file, if you
fprintf(fid, '\n') then you will get just a linefeed (character #10) at
that position. With a text file, if you do the same thing and you are
using Windows, then you would get a carriage return followed by a linefeed.
In Windows, there is an additional difference when reading text files:
if an EOF character (control-Z, character #26) is encountered in text
mode, it will be treated as indicating end of file even if there is more
present in the file. This behaviour should not happen in Unix but I have
not tested that point.
If you have an existing binary file and you wish to write further data
to it but in text mode, then fopen() the file with 'at' permissions
instead of 'wb'.
Note: it is probably a bad idea to use a .mat file extension for a file
that is not a Matlab .mat save() file.
|
|
0
|
|
|
|
Reply
|
Walter
|
11/24/2010 5:38:31 PM
|
|
|
3 Replies
685 Views
(page loaded in 0.189 seconds)
Similiar Articles: fscanf and newline - comp.soft-sys.matlab... character - comp.lang.java.help fscanf and newline - comp.soft-sys.matlab Howto read newline character - comp.lang.java.help how to write ASCII data using FWRITE function ... fwrite help on Serial Port - comp.soft-sys.matlab... three data bytes? Do I need brackets? Should I use int8 or uint8? Does fwrite ... port in ascii ... fwrite (serial) - Write binary data to device This MATLAB function writes ... Howto read newline character - comp.lang.java.helpHi, I'm new to java and I'm writing a simple text editor using swt ... technique - look carefully at the data that ... character - comp.lang.java.help how to write ASCII ... RS-232 problems - comp.soft-sys.matlab... fwrite(s,'AbCdE'); But my goal is to send directly binary data. So now I fist transform my binary ('110110') into ASCII ... using a USB to serial converter. If you write ... write a cell array to text file.. - comp.soft-sys.matlab ...... at+');' and > then i try fwrite ... convert mat files (struct) to ascii text files / save data as ... write ... into an ASCII format file using ... Write matrix to ASCII ... Fastest way to save data? - comp.soft-sys.matlab... collect more data. Currently I am using the save function ... of on the writing itself. If you're only passing data ... Store the data as 1-byte characters, and use FWRITE to ... how to prevent ml from saving ascii in scientic notation - comp ...... test.csv',M); the data is saved in ascii ... 5}; D(:,6) = data{1,6}; D(:,7) = data{1,7}; and then i write the ... that take cell as argument to file write function ... Diehard tests - comp.soft-sys.matlabI need advice on how to write a binary file ... Pool((rand(1, 1e6) > 0.5) + 1); % Test data S ... random number procedure to an ordinary ascii file. Then use ... Serial port Reading - comp.soft-sys.matlab... that any lower ASCII ... from a port and write to a file is to use a callback function that is executed when you receive data. ... bytes); fwrite(appenderFile, data ... translations of creat() and write() to ISO C - comp.unix ...... the output_file in write(...)? Unless you want to lose data and leak memory, yes. You could also use ... ISO C, it's a POSIX function ... Writing non ASCII text files - comp ... how to write ASCII data using FWRITE function - Newsreader ...Subject: how to write ASCII data using FWRITE function. From: Darlling5147 Sew. Date: 24 Nov, 2010 07:52:05. Message: 1 of 4 Is it possible to write data to a text file using "fwrite ...Is it possible to write data to a text file using "fwrite" function in C ... Optimise text file ascii writing from large a... Reading and ... 7/25/2012 5:50:06 PM
|