Having a .mat file store an image to call to a tab in app designer

4 visualizaciones (últimos 30 días)
Katlynn
Katlynn el 11 de Feb. de 2025
Respondida: Walter Roberson el 11 de Feb. de 2025
Hello, any help is appreciated. A litle background. I am trying to make a GUI that uses a scenario file in the form of a .mat, that has a bunch of info that gets pulled into different places withing the app designer. I was asked to see if we could put an image into the .mat file and call it on a seperate tab. This image is to reflect the scenario as a reference. (disclaimer I am still new to MALAB)
I have used this code here to get the image into the .mat:
new_image = imread(' insert_location');
% Add the image to the workspace as a new variable
new_image_variable = 'Schematic';
% Save the updated data to the .mat file
save('name.mat', 'new_image_variable', '-append');
This seems to have added the variable, but when I make a seperate tab I can not figure out how to load the image.
...this is for the button option in the component library
I have used this code here:
% Button pushed function: SpacecraftSchematicButton- this is generated by app designer and cant be changed
function SC_Schematic(app, event)
% In the tab where you want to use the variable
function PrivateButtonPushedFcn(app, event)
image_data = app.UserData.new_image_variable;
img = uiimage(app.UIFigure);
img.Position = [100 100 200 200]; % Set the position and size of the image
img.ImageSource = image_data;
end
... I have also tried this with the image option in the component library.
....and nothing happens. I had it before so that you could just select the image with the image component and manually update it, but the ask was to make it a little more automated. Ideally if I could just have the image pop up without having to push anythign that would be wonderful, just load the .mat file and then the image would load accoringly. Any

Respuestas (1)

Walter Roberson
Walter Roberson el 11 de Feb. de 2025
new_image_variable = 'Schematic';
% Save the updated data to the .mat file
save('name.mat', 'new_image_variable', '-append');
That stores new_image_variable in name.mat -- but new_image_variable is just a character vector, not the content of an image.
You do not appear to be storing new_image_variable into app.UserData.new_image_variable
You want something more like
save('name.mat', 'new_image_variable', 'new_image', '-append');
and later
image_data = load('name.mat', 'new_image').new_image;
img.ImageSource = image_data;
Notice that the actual image data is being stored in ImageSource.
uiimage() ImageSource can be either a file path or else it can be RGB data (support for grayscale is not documented.). If it is a file path then it must be the path to an image file. Using the file path to a .mat file is not a supported option.
Instead of storing the image data you could store the information about ' insert_location'

Etiquetas

Productos


Versión

R2024b

Community Treasure Hunt

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

Start Hunting!

Translated by