I am trying to read accelerometer data from a csv file in matlab using xlsread with [num text raw]. However,the raw field only gives [NaN] instead of the text and character data that I am expecting. How can this be rectified? Any other ways to read hexadecimal data from a csv file?? Thanks in advance! What you should do is use the table variable, read the item in and then use hex2dec. Stack Overflow for Teams — Collaborate and share knowledge with a private group. Create a free Team What is Teams?
Collectives on Stack Overflow. Based on your location, we recommend that you select:. Select the China site in Chinese or English for best site performance. Other MathWorks country sites are not optimized for visits from your location. Search Answers Clear Filters. Answers Support MathWorks. Search Support Clear Filters. Support Answers MathWorks. Search MathWorks. Hexadecimal is a way to represent numbers in base It can be represented using unsigned integers from 0 to , eight symbols 0 or 1, two hex symbols, etc.
The hex representation is generally used because it is compact two symbols vs eight for binary or max 3 for integers. You attached a CSV file to your question, which stores an hex representation of the data.
Each representation of a byte is coded with two hex symbols, and successive representations of successive bytes are separated by commas D3,AA,24,FF,.. Now we all asked questions related to what was the actual format of your data and whether hex was just a representation or really the aforementioned format. The reason is that some people open files with hex editors, see hex code and say that they have hex data, but they don't; the hex editor is just representing bytes in hex.
Looking at the CSV file that you provided, I see that it contains the hex representation stored as characters internally, of course, these are bytes, but we read them and interpret them as ASCII codes, and we display the hex representation. This seems to be working?
Now I still have no clue about the content of the. Finally, I apologize about buffer. I am not using the function of the Signal Processing Toolbox , but I am using it as a variable name. It is a bad habit that I took at a time when I didn't have this toolbox.. Cedric Wannaz on 13 Aug PS: if you don't understand the detail of what my solution does, try on a small example:. This is a string, where we insert a carriage return and a new line at the end of each line.
There are many ways to display the ASCII codes, one way is to typecast to numeric double by adding 0 number to the string. Let's test with the first upper case letters ABC :. What about characters '' etc? Here you recognize 48 for the first '0', etc. So our first move if we want to keep the hex characters only is to pick all elements whose ASCII code is above 47 which eliminate commas, carriage returns, and new lines :.
And then we convert buf to numeric, subtract the ASCII code of '0' to characters that were coding digits this remaps into , etc. More Answers 0. See Also. Tags dlmread fscanf importing hex data text file. Start Hunting! Similar threads T. PC Programming and Interfacing. How to read data via serial port in Matlab?
Started by enogogo Jun 17, Replies: 2. Part and Inventory Search. Welcome to EDABoard. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register. By continuing to use this site, you are consenting to our use of cookies. Accept Learn more….
0コメント