Error using h5readc Unable to open the file because of HDF5 Library error. Reason:Unknown

65 views (last 30 days)
I've just installed Matlab 2021 b to run a pre-written code and when I try to run it (the only thing I've added to the code is the file location link) Matlab gives me this error:
"Error using h5readc
Unable to open the file because of HDF5 Library error. Reason:Unknown"
related to the Matlab function code of h5read.m, line 93: [data,var_class] = h5readc(Filename,Dataset,start,count,stride);
Does anybody have any idea of what is the problem? It seems to be internal to Matlab, may it be?
Thank you,
Giulia

Answers (2)

Cris LaPierre
Cris LaPierre on 22 Jan 2022
If you can share your file, we can test if we get the same error. However, I would probably go straight to contacting support.
  2 Comments
Zeynep Berra
Zeynep Berra on 8 Nov 2023
Hi, I am having the same problem with the code provided on the code in this link:https://github.com/MagneticParticleImaging/MDF/blob/master/matlab/reco.m.
I deleted the download rows and placed the mdf files by myself. Also, I am using MATLAB r2023b Academic Use currently. My friend did not get the error message with r2020b, however, I want to run the code on my PC. Any thoughts?
Cris LaPierre
Cris LaPierre on 8 Nov 2023
I am not able to duplicate the error on my desktop or here (see below). I recommend contacting support so they can look into it further.
%% 1. Loading the required external functions
clear all
close all
%% 2. Download measurement and systemMatrix from http://media.tuhh.de/ibi/mdf/
filenameSM = 'systemMatrix.mdf';
filenameMeas = 'measurement.mdf';
websave(filenameSM,'http://media.tuhh.de/ibi/mdfv2/systemMatrix_V2.mdf')
ans = '/users/mss.system.iyUKxB/systemMatrix.mdf'
websave(filenameMeas,'http://media.tuhh.de/ibi/mdfv2/measurement_V2.mdf')
ans = '/users/mss.system.iyUKxB/measurement.mdf'
%% 3. Loading the data
% For the System matrix (later named SM)
% to obtain infos on the file, use the command: infoSM = h5info(filename_SM);
% or read the format documentation
% read the data, saved as real numbers
S = h5read(filenameSM, '/measurement/data');
% reinterpret as complex numbers
S = complex(S.r,S.i);
% get rid of background frames
isBG = h5read(filenameSM, '/measurement/isBackgroundFrame');
S = S(isBG == 0,:,:,:);
% For the measurements
% read and convert the data as complex numbers
% note that these data contain 500 measurements
u = h5read(filenameMeas, '/measurement/data');
%u = squeeze(u(1,:,:,:) + 1i*u(2,:,:,:));
u = fft(cast(u,'double'));
u = u(1:(size(u,1)/2+1),:,:,:);
%% 4. Pre-process - Remove the frequencies which are lower than 30 kHz, as they are unreliable due to the anologue filter in the scanner
% generate frequency vector
numFreq = h5read(filenameMeas, '/acquisition/receiver/numSamplingPoints')/2+1;
rxBandwidth = h5read(filenameMeas, '/acquisition/receiver/bandwidth');
freq = linspace(0,1,numFreq) .* rxBandwidth;
% we supose that the same frequencies are measured on all channel for
% the SM and the measurements. use only x/y receive channels
idxFreq = freq > 80e3;
S_truncated = S(:,idxFreq,1:2);
u_truncated = u(idxFreq,1:2,:);
%% 5. Merge frequency and receive channel dimensions
S_truncated = reshape(S_truncated, size(S_truncated,1), size(S_truncated,2)*size(S_truncated,3));
u_truncated = reshape(u_truncated, size(u_truncated,1)*size(u_truncated,2), size(u_truncated,3));
%% 6. Averaged the measurement used for the reconstruction over all temporal frames
u_mean_truncated = mean(u_truncated,2);
%% 7. Make two simple reconstructions
% a normalized regularized kaczmarz approach
c_normReguArt = kaczmarzReg(S_truncated(:,:),...
u_mean_truncated(:),...
1,1*10^-6,0,1,1);
% and an regularized pseudoinverse approach
[U,Sigma,V] = svd(S_truncated(:,:).','econ');
Sigma2 = diag(Sigma);
c_pseudoInverse = pseudoinverse(U,Sigma2,V,u_mean_truncated,5*10^2,1,1);
%% 8. Display an image
% read the original size of an image
number_Position = h5read(filenameSM, '/calibration/size');
figure
subplot(1,2,1)
imagesc(real(reshape(c_normReguArt(:),number_Position(1),number_Position(2))));
colormap(gray); axis square
title({'Regularized and modified ART - 3 channels';'1 iterations / lambda = 10^{-6} / real part'})
subplot(1,2,2)
imagesc(real(reshape(c_pseudoInverse(:),number_Position(1),number_Position(2))));
colormap(gray); axis square
title({'Pseudoinverse - 3 channels';' lambda = 5*10^{3} / real part'})
function [ x ] = kaczmarzReg( A,b,iterations,lambd,shuff,enforceReal,enforcePositive )
% regularized Kaczmarz
% As published here: http://iopscience.iop.org/article/10.1088/0031-9155/55/6/003/meta on page 1582.
% Other references : Saunders M 1995: Solution of sparse rectangular
% systems using LSQR and CRAIG
% or
% From Dax A 1993: On row relaxation methods for large constrained
% least squares problems
% initialization of the variable
[N, M] = size(A);
x = complex(zeros(N,1));
residual = complex(zeros(M,1));
rowIndexCycle = 1:M;
% calculate the energy of each frequency component
energy = rowEnergy(A);
% may use a randomized Kaczmarz
if shuff
rowIndexCycle = randperm(M);
end
% estimate regularization parameter
lambdZero = sum(energy.^2)/N;
lambdIter = lambd*lambdZero;
for l = 1:iterations
for m = 1:M
k = rowIndexCycle(m);
if energy(k) > 0
tmp = A(:,k).'*x;
beta = (b(k) - tmp - sqrt(lambdIter)*residual(k)) / (energy(k)^2 + lambdIter);
x = x + beta*conj(A(:,k));
residual(k) = residual(k) + beta*sqrt(lambdIter);
end
end
if enforceReal && ~isreal(x)
x = complex(real(x),0);
end
if enforcePositive
x(real(x) < 0) = 0;
end
end
end
function [ c ] = pseudoinverse( U,Sigma,V,u,lambd,enforceReal,enforcePositive )
% This algorithm solves the Thikonov regularized least squares Problem
% argmin(?Ax-b?� + ??b?�) using the singular value decomposition of A.
% Arguments
% `U,Sigma,V`: Compact singular value decomposition of A
% `u`: Measurement vector u
% `lambd`: The regularization parameter, relative to the matrix trace
% `enforceReal::Bool`: Enable projection of solution on real plane during iteration
% `enforcePositive::Bool`: Enable projection of solution onto positive halfplane during iteration
D = zeros(length(Sigma),1);
for i=1:length(Sigma)
D(i) = Sigma(i)/(Sigma(i)^2+lambd^2);
end
% calculate pseudoinverse
tmp = U'*u(:); % gemv('C',...) conjugate transpose
tmp = tmp.*D;
c = V*tmp; % gemv('N',...) not transposed
% apply constraints
if enforceReal
c = real(c);
end
if enforcePositive
idxNega = real(c)<0;
c(idxNega) = 0;
end
end
function [ energy ] = rowEnergy(A)
% Calculate the norm of each row of the input
% This is an image of the energy stored by each frequency component
% but the scaling is unclear.
energy = sqrt(sum(abs(A.*A),1));
end

Sign in to comment.


Thomas Ulrich
Thomas Ulrich on 21 Mar 2022
I'm also seeing this exact error in Matlab R2021b with some code that previously ran without error on older Matlab versions. Unfortunately, I also haven't figured out yet what's wrong.

Products


Release

R2021b

Community Treasure Hunt

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

Start Hunting!