can display .mat files into gui matlab?

4 次查看(过去 30 天)
I create .mat files and can display into gui matlab? I want the figure to be displayed on gui matlab.

回答(2 个)

Anudeep Kumar
Anudeep Kumar 2025-6-2
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 2025-6-2
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.

类别

Help CenterFile Exchange 中查找有关 File Operations 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by