MATLAB: Convert JPEG slices to volume

3dimagematlab gui

in a GUI, the user have to upload a 3D image then the slices will show using a slider. the formats can be .dcm, .img or .jpeg
.jpeg format, the image is not a 3d (volume) it is number of slices!
for that i need to convert these slices to volume, Knowing that the number of slices is differ depending on the uploaded image.