필터 지우기
필터 지우기

How can I "reshape" a data set?

조회 수: 3 (최근 30일)
Art
Art 2015년 6월 19일
답변: Walter Roberson 2015년 6월 19일
This is probably simple: I have a data file of decimals, each one equal to 1 byte:
0
0
3
127
Each variable I have is n bytes long, so I need to read 'n' bytes of this data and convert it into a single number. I can do this by (assume n = 4 and little endian):
4byte_var = hex2dec(strcat(dec2hex(datastream(12),2),dec2hex(datastream(11),2),dec2hex(datastream(10),2),dec2hex(datastream(9),2)))
This changes the dec values to hex, strcats them together, then changes the entire hex string back to decimal.
I've tried using reshape and shiftdata to automatically rearrange the data so I can do this whole step "eloquently", but I've failed to find a solution.

채택된 답변

Walter Roberson
Walter Roberson 2015년 6월 19일
swapbytes(typecast(uint8(YourVectorOfBytes), 'uint32'))

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Numeric Types에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by