dsp.MatFileReader HDF5 library encountered an error
5 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hi all, I am getting this error with MatFileReader which I don't know how to fix. The function below simply reads a mat file with dsp.MatFileReader.
S.A = randn(1000,1);
S.B = randn(1000,1);
save('sampleS.mat','S','-v7.3');
clear S;
filename = 'sampleS.mat';
VariableName = 'S';
SamplesPerFrame = 50;
mfr = dsp.MatFileReader;
mfr.Filename = filename;
mfr.VariableName = VariableName;
mfr.SamplesPerFrame = SamplesPerFrame;
while ~isDone(mfr)
x= mfr();
d = x.A;
end
Error using dsp.MatFileReader/setupObject (line 195)
The HDF5 library encountered an error and produced the following stack trace information:
H5D__open_name not a dataset
Error in dsp.MatFileReader/setupImpl (line 212)
setupObject(obj,varargin);
Error in matlab.system.mixin.FiniteSource/isDone
Error in untitled (line 17)
while ~isDone(mfr)
0 commentaires
Réponses (1)
Gyan Vaibhav
le 29 Déc 2023
Hi dleal,
I understand that you are trying to read a mat file with dsp.MatFileReader. However, you are not able to do it, and the error mentioned above occurs while running the given code.
The error encountered with “dsp.MatFileReader” suggests that it is having trouble reading the specified variable from the “MAT” file. This might be due to the way the data is structured within the “MAT” file.
Specifically, the “dsp.MatFileReader” expects the variable to be a matrix or an array, but in this case, “S” is a structure containing two fields “A” and “B”.
To fix this issue, its necessary to save the fields of the structure “S” as separate variables in the “MAT” file.
Here's how the code can be modified to do that:
S.A = randn(1000,1);
S.B = randn(1000,1);
A = S.A; % Separate the fields into individual variables
B = S.B;
save('sampleS.mat','A','B','-v7.3'); % Save the individual variables
clear S A B;
filename = 'sampleS.mat';
VariableName = 'A'; % Set the variable name to one of the variables saved
SamplesPerFrame = 50;
mfr = dsp.MatFileReader(filename, 'VariableName', VariableName, 'SamplesPerFrame', SamplesPerFrame);
while ~isDone(mfr)
x = mfr();
d = x; % x is now directly the variable A, since that's what we're reading
end
The above snippet separates the fields “A” and “B” into individual variables, and the code shows expected results.
Please go through the following documentation for more information on “dsp.MatFileReader”:
Hope this helps.
Thanks
Gyan
0 commentaires
Voir également
Catégories
En savoir plus sur Linear Prediction dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!