can display .mat files into gui matlab?

4 views (last 30 days)
Rega
Rega on 11 Mar 2021
Answered: Walter Roberson on 2 Jun 2025
I create .mat files and can display into gui matlab? I want the figure to be displayed on gui matlab.

Answers (2)

Anudeep Kumar
Anudeep Kumar on 2 Jun 2025
Hey Rega,
I recently worked on something similar. I believe you can load any .mat file by first creating an appropriate GUI with the correct components and then using the 'uigetfile' function.
Assuming you have an 'UITable' and a 'Button' Component added to your MATLAB App in App Designer.
Below is the code which you can use in your Button Push Callback function
function LoadButtonPushed(app, event)
[file, path] = uigetfile('*.mat');
if isequal(file, 0)
return; % User canceled
end
fullPath = fullfile(path, file);
data = load(fullPath);
% Example: Display a variable in a UITable if it's a matrix
if isfield(data, 'myMatrix') && isnumeric(data.myMatrix)
app.UITable.Data = data.myMatrix;
end
end
This is how I created a 5x4 Sample marix
% Define a 5x4 numeric matrix
myMatrix = [
1, 2, 3, 4;
5, 6, 7, 8;
9, 10, 11, 12;
13, 14, 15, 16;
17, 18, 19, 20
];
% Save the matrix to a .mat file
save('table_data.mat', 'myMatrix');
Additionally I have added the documentation for 'uigetfile' for your reference.
I hope this helps!

Walter Roberson
Walter Roberson on 2 Jun 2025
Generally speaking, you cannot display .mat files in a GUI. .mat files generally contain collections of variables, but you can generally only display a single variable for any one plotting call. Also, .mat files generally can contain variables that are object-oriented objects or contain non-numeric data, and those non-numeric data items cannot be displayed without processing. It is even possible to store MATLAB figure() or uifigure() objects in .mat files
You would need to narrow down your situation, describing what the .mat files contain, in order for us to give a meaningful answer.

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!