Skip to content

mat v4 compat: read namelen with given length and strip trailing null #202

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

songjhaha
Copy link

@songjhaha songjhaha commented Mar 7, 2025

we have some old mat file,but the name is store without null-terminator '\0'(it could be create from some old c program).

MATLAB and scipy is compat with these file.

here is a test .m script to generate example mat file:

fid = fopen('testnamelen_4.2c_SOL2.mat', 'wb')
data = rand(1,9);
[M, N] = size(data);
data_type = 0;
prec = 'double';
name = 'testnamelen';

L = length(name);

fwrite(fid, data_type, 'int32');

fwrite(fid, M, 'int32');

fwrite(fid, N, 'int32');
fwrite(fid, 0, 'int32');
fwrite(fid, L, 'int32');
fwrite(fid, name, 'uint8');
fwrite(fid, data, prec);

data1 = load('testnamelen_4.2c_SOL2.mat');

assert(all(data1.(name)==data))

@songjhaha
Copy link
Author

@ViralBShah could you review this PR?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant