필터 지우기
필터 지우기

.csv file hex to dec converting(hex2dec is not working)

조회 수: 4 (최근 30일)
Jeong Dae Kim
Jeong Dae Kim 2021년 11월 10일
댓글: Walter Roberson 2021년 11월 10일
hi. i'm converting .csv file (hex) to .csv file (dec).
if a.csv file is hexadecimal
a.csv file :
['eb','80','80' ; 'eb','80','80' ...]
A = hex2dec('a.csv')
error : Error using hex2dec
Hexadecimal text must consist of characters 0-9 and A-F.
always error occurs.

채택된 답변

Walter Roberson
Walter Roberson 2021년 11월 10일
You cannot apply hex2dec to a file name . You need to read the hex data out of the file first and convert that if you are going to use hex2dec .
Could you confirm that the csv file contains both commas and semi-colons ? Are the semi-colons after every third entry exactly? Or is the actual input like
'eb', '80', '80'
'eb', '80', '80'
with no '[' and no semi-colon ?
Is there the same number on every line? Is there indeed multiple lines?
  댓글 수: 2
Jeong Dae Kim
Jeong Dae Kim 2021년 11월 10일
and i can add (') if it is important, i attempted readtable() but there is NaN
Walter Roberson
Walter Roberson 2021년 11월 10일
in_filename = 'outfile_ycbcr.csv';
out_filename = 'ycbcr_dec.csv';
[fid, msg] = fopen(in_filename, 'r');
if fid < 0
error('failed to open file "%s" because "%s"', in_filename, msg);
end
data_dec = cell2mat(textscan(fid, '%x, %x, %x'));
fclose(fid);
writematrix(data_dec, out_filename);

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

추가 답변 (1개)

KSSV
KSSV 2021년 11월 10일
You cannot convert like that.
  1. Read the csv file data using csvread or readtable.
  2. Then on the data use the function hex2dec
  3. Then write converted data into csv file using write2table
  댓글 수: 1
Jeong Dae Kim
Jeong Dae Kim 2021년 11월 10일
if i use readtable, element with alphabet changes to NaN

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

카테고리

Help CenterFile Exchange에서 Data Type Conversion에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by