將 hex檔案匯入到Matlab中

2021-07-28 12:17:02 字數 997 閱讀 2743

硬體產生的資料通常而言是二進位制或者十六進製制,例如:檔案格式為.hex,需將其儲存為.txt格式(也可以複製到word中,自動分行,然後複製到.txt文字中)。

讀取二進位制txt檔案:

假如txt文件中內容為0001 0010 0011 0100 1000,儲存在pin.txt文件中

使用

a=textread('pin.txt','%s')'

a =

'0001' '0010' '0011' '0100' '1000'

可以看到

資料儲存為了char

格式。使用bin2dec

b=bin2dec(a)'

b = 1 2 3 4 8

可以看到成功地轉換成了十進位制檔案。

十六進製制檔案:

0001 0010 0011 0100 1000 a b c aa

a=textread('pin.txt','%s')'

a =

'0001' '0010' '0011' '0100' '1000' 'a' 'b' 'c' 'aa'

可以看到成功讀取了檔案。

b=hex2dec(a)'

b = 1 16 17 256 4096 10 11 12 170

讀取完畢。

將16進製制資料轉換成10進製後還需要將資料進行儲存。可以用dlmwrite函式:

dlmwrite('c:\b.txt',b,'delimiter', ' ')	 %將得出資料存入新的b.txt文件

將stdout stderr匯入到指定檔案

在編寫程式中,經常用到stdout stderr作為輸出,通常stdout用於輸出程式執行正常時的資訊,stderr用於輸出程式出錯時的資訊。我們可以通過一些命令將stdout stderr在螢幕上的輸出匯入到指定的檔案。1 準備工作 帶有stdout stderr輸出的test.cpp test....

將csv檔案匯入到mysql

首先,為自己要匯入的檔案按照屬性建立好錶 mysql create table id int notnull primary key,name char 30 character set utf8 not null level char 30 character set utf8 not null,...

將excel中的資料匯入到matlab中

1 將excel中的資料匯入到matlab中 方法一 將excel中 的資料匯入到matlab中採用matlab庫函式xlsread 1 c xlsread filename.xls 2 c xlsread filename.xls range 表示讀取excel的range範圍,range的範圍是...