How do I display .mat file as an image in Matlab
9 views (last 30 days)
Show older comments
Hi All Matlab users,
I have a .mat file ... I would like to convert it to png file but I have a problem with display it.
src_folder = 'D:/14.3D/1/';
dst_folder = 'D:/14.3D/1';
files = dir(fullfile(src_folder, 'OD.mat'));
% Loop through each file
for i = 1:length(files)
% Load the .mat file
load(fullfile(src_folder, files(i).name));
% Convert the data to uint8
I = reshape(uint16(linspace(0,65535,25)),[5 5])
example_matrix = im2uint8(1);
example_matrix = im2uint8(example_matrix);
% Construct the destination file name
[~, name, ~] = fileparts(files(i).name);
dst_file = fullfile(dst_folder, [name '.png']);
% Try to save the image
try
imwrite(example_matrix, dst_file);
disp(['Image ' name ' saved successfully']);
catch
disp(['Error saving image ' name]);
end
end
The image show it stae is empy. Could someone help me please ? I would appreciate for any help.
3 Comments
Answers (1)
See Also
Categories
Find more on File Operations in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!