How can I load a .mat struct?

1 次查看(过去 30 天)
Hello community:
I use Matlab 2021a and when I try to load a .mat struct with these sentences load('linesStruct_1.mat') or load('linesStruct_1') I receive the following message:
Error using load
Unable to read MAT-file C:\ ... linesStruct_1.mat. Not a binary MAT-file. Try load -ASCII to
read as text.
Error in drawpoint_Algoritmo_Rename_Struct_Pendiente (line 5)
load('linesStruct_1.mat');
Could it be because I have saved the structures with a different name (lines in place of linesStruct_1.mat) than the image? Or maybe it has to do with the shortcut icons that appear in my folders?.
I remember this was not happening in other versions. I have been reading the many cases in which this occurs but I can not find a solution according to my situation. Any idea?
Thank you very much.

采纳的回答

Walter Roberson
Walter Roberson 2021-6-26
The file is not a .mat file. At the moment we do not know what it is. Experiment with
filename = 'linesStruct_1.mat';
if isunix()
filename = 'handel.mat';
end
[fid, msg] = fopen(filename, 'r');
if fid < 0
error('could not open file "%s" because "%s"', filename, msg);
end
bytes = fread(fid, [1 100], '*uint8');
fclose(fid)
ans = 0
fprintf('first part of file as text:\n');
first part of file as text:
fprintf('%s\n', char(bytes));
MATLAB 5.0 MAT-file, Platform: GLNX86, Created on: Tue Mar 9 11:01:23 2004
fprintf('\nas decimal: \n');
as decimal:
disp(bytes);
Columns 1 through 33 77 65 84 76 65 66 32 53 46 48 32 77 65 84 45 102 105 108 101 44 32 80 108 97 116 102 111 114 109 58 32 71 76 Columns 34 through 66 78 88 56 54 44 32 67 114 101 97 116 101 100 32 111 110 58 32 84 117 101 32 77 97 114 32 32 57 32 49 49 58 48 Columns 67 through 99 49 58 50 51 32 50 48 48 52 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 Column 100 32
fprintf('\nas hex: \n');
as hex:
fprintf('%02x ', bytes);
4d 41 54 4c 41 42 20 35 2e 30 20 4d 41 54 2d 66 69 6c 65 2c 20 50 6c 61 74 66 6f 72 6d 3a 20 47 4c 4e 58 38 36 2c 20 43 72 65 61 74 65 64 20 6f 6e 3a 20 54 75 65 20 4d 61 72 20 20 39 20 31 31 3a 30 31 3a 32 33 20 32 30 30 34 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
fprintf('\n');
The bit about isunix() is my substituting a different file for the purpose of demonstration here.
You are hoping to see the text version start with 'MATLAB 5.0' or 'MATLAB 7.3' . If you show us the three parts of the output we might be able to tell you what kind of file you actually have instead of a .mat file.
  7 个评论
Walter Roberson
Walter Roberson 2021-6-29
I am not clear as to whether the problem is solved?
David Ruiz Velasco
David Ruiz Velasco 2021-6-29
Hello.
Yes, it is solved.
Thank you very much.

请先登录,再进行评论。

更多回答(0 个)

产品


版本

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by