Loading hex values from a file vs executing .m file that contains same values

I have a file: test_hex_load.m
that contains one line
0x52d50
When I try to load the file, instead of just executing the m-file, it does not give the same result and I was wondering why that would be?
>> clear
>> test_hex_load
ans =
uint32
339280
>> load("test_hex_load.m")
>> test_hex_load
test_hex_load =
339536

4 件のコメント

Stephen23
Stephen23 2024 年 4 月 24 日
"I was wondering why that would be?"
Because LOAD is the wrong tool for the job. The fact that LOAD can import text data is merely a historical oddity, a remnant from long ago when MATLAB was a much simpler tool and there were far fewer file formats to import. LOAD has absolutely no documented behavior for hexadecimal values written using the notation you show. In fact, the LOAD documentation only states that "ASCII files must contain a rectangular table of numbers, with an equal number of elements in each row. The file delimiter (the character between elements in each row) can be a blank, comma, semicolon, or tab character. The file can contain MATLAB comments (lines that begin with a percent sign, %)."
Nothing about hexadecimal there.
Emmanuelle Laprise
Emmanuelle Laprise 2024 年 4 月 24 日
It's unfortunate that it doesn't (and wasn't meant to) work. It would be a nice feature. In the 2000 numbers that I imported that way, half of them were correct and most of the others were very close. Even though it was not documented, it seemed to work. An error message, or a warning, would have been useful.
Stephen23
Stephen23 2024 年 4 月 24 日
@Emmanuelle Laprise: you could make an enhancement request:
But it is more likely that this feature would be included in the modern, more powerful text importing functions (e.g. READMATRIX, READTABLE, etc). This topic has been discussed before, with alternative solutions:
Emmanuelle Laprise
Emmanuelle Laprise 2024 年 4 月 24 日
Thank you for the links. I apologize for the repost. I had not found these questions/answers when searching the database.

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

 採用された回答

Walter Roberson
Walter Roberson 2024 年 4 月 24 日

0 投票

It's a bug. It is processing all d and D as if they were e

その他の回答 (0 件)

製品

リリース

R2023b

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by