Importing hex values from a .txt or .xlsx file

I have a function as detailed below:
function [A B C] = elevation (d,p,t)
FC = 360;
d = hex2dec (d);
p = hex2dec (p);
t = hex2dec (t);
A = (d*0.5*FC/2^18);
B = (p*0.5*FC/2^15);
C = (t*0.5*FC/2^15);
I am looking to take the input hex values (d, p, t) from a txt file or spreadsheet although i don't seem to be able to import any values that contain letters.
Does anyone have any ideas where i am going wrong? Should i add additional lines of code to the function to import the data or import the data from the command window?
Any help is much appreciated

답변 (1개)

José-Luis
José-Luis 2013년 2월 18일

0 개 추천

doc sscanf
You can use the '%x' identifier for hexadecimal data.

댓글 수: 4

Darren
Darren 2013년 2월 18일
편집: Darren 2013년 2월 18일
How does that assist in importing data from txt files or spreadsheets? Would i not need to use importdata(.txt) or xlsxread?
José-Luis
José-Luis 2013년 2월 18일
편집: José-Luis 2013년 2월 18일
Sorry, I meant fscanf().
For text files the documentation of fscanf() gives several examples on how to import data. For excel data, you would first need to import the data to matlab. You could use xlsread() for that. Then you could convert to hexadecimal, sscanf(some_string,'%x').
The actual code would depend on the structure of your data.
the data i am trying to import is:
d p t
001C72 038E 0392
FFE38D FC71 FC6D
hey,i'm facing the same issue.were you able to resolve it??

댓글을 달려면 로그인하십시오.

카테고리

질문:

2013년 2월 18일

댓글:

2016년 8월 15일

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by