MATLAB EXERCISES 4
Download the file textread_eg.txt and save it to a convenient directory on your PC (and change the current working directory for matlab to the same directory); the file contains the text:
sample Time data
1 08:00:00 1.8449
2 08:00:30 5.712
3 08:01:00 9.9805
4 08:01:30 17.6319
5 08:02:00 25.9215
6 08:02:30 36.9147
7 08:03:00 49.9014
8 08:03:30 64.8244
9 08:04:00 82.8032
10 08:04:30 100.0112
Try reading the data in to matlab so that you have separate variables containing the sample number, hours, minutes, seconds, and data. You can do this using individual commands on the command line, or by writing a short function. It's probably easier to work on the command line first, and then put everything in a function once you've figured out what you're doing. [HINT]
Remember: fid = fopen(filename) - to open file
fclose(fid) – to close file when done (or to start over)
[answer - command line] [answer - function]
Download the files: binarytest_uchar.bin & binarytest_float32.bin and save them to your working directory,
Each contains an array of 20 data values:
2 3 4 5 6 7 8 9 10
4 9 16 25 36 49 64 81 100
the first file as unsigned 8bit integers (uchar) the second as 32-bit floating point numbers (float32). Try reading in the data – once you've succeeded, try reading them in with the wrong format specifier and see what you get (getting scrambled data when reading from binary files is a good inicator that you've got the format specified wrongly)
[a typical failed first attempt example] [correct answers]