Read text without converting to date

2 ビュー (過去 30 日間)
Daniel
Daniel 2023 年 9 月 27 日
コメント済み: Walter Roberson 2023 年 9 月 27 日
I'm using both csvread and xlsread to read in a .csv file with hex data as text. Two of the values are '7DEC' and 'FEB6', but they are being auto-converted to '12/7/2023' and '2/6/2023' in the output cell. Is there a way to prevent this?
  2 件のコメント
Dyuman Joshi
Dyuman Joshi 2023 年 9 月 27 日
Use readtable instead both of the deprecated functions.

サインインしてコメントする。

回答 (2 件)

Voss
Voss 2023 年 9 月 27 日
Try using readcell or readtable.
file = 'test.csv';
% show file contents:
type(file)
7DEC,FEB6
% read file into a cell array C:
C = readcell(file)
C = 1×2 cell array
{'7DEC'} {'FEB6'}

dpb
dpb 2023 年 9 月 27 日
writematrix(["7DEC","FEB6","FFFE","ABCD"],'test.csv')
type test.csv
7DEC,FEB6,FFFE,ABCD
data=readcell('test.csv')
data = 1×4 cell array
{'7DEC'} {'FEB6'} {'FFFE'} {'ABCD'}
fid=fopen('test.csv','r');
data=textscan(fid,'%x','delimiter',',')
data = 1×1 cell array
{4×1 uint64}
fid=fclose(fid)
fid = 0
data{:}
ans = 4×1
32236 65206 65534 43981
Depending upon whether you want it converted or not on input.
NOTA BENE: Both csvwrite and xlsread have long been deprecated...

カテゴリ

Help Center および File ExchangeSpreadsheets についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by