Update Webdesigner App Image component- how??

4 vues (au cours des 30 derniers jours)
Kenneth
Kenneth le 13 Mar 2024
Commenté : Kenneth le 14 Mar 2024
I've made a gui and it has an image component that i would like for the image to update automatically (without me having to click it). I've made a matlab scrip that produces a plot and i would like the image component in the gui to update once the image is ploted and stored in some folder. I have a button in the gui called "calculate" and once its clicked that runs the external matlab scrip the creates the plot and saves it as a png. for some reason i can't get the image component to update. is this even possible?

Réponses (1)

Kojiro Saito
Kojiro Saito le 14 Mar 2024
To update an image of uiimage component, change the ImageSource property.
app.Image.ImageSource = 'test.jpg'
But it does not refresh when the image file name is the same as described in Why does uiimage does not update when the file linked to ImageSource changes?
So, if you're using the same file name as an input of ImageSource, imread would do the trick.
testScript; % Run some script and out.jpg will be stored in image folder
app.Image.ImageSource = imread('image/test.jpg'); % Read the image and refresh the Image Component
  1 commentaire
Kenneth
Kenneth le 14 Mar 2024
I tried implenting that into the code.
i created my own public property inside the appdesigner:
%
properties (Access = public)
directory = 'C:\Desktop\Plot\'; % Define the director
end
methods (Access = public)
function updateImage(app, filename)
fullFilePath = fullfile(app.directory, filename); % Create the full file path
app.Image2.ImageSource = imread(fullFilePath); % Load and display the image
end
end
and in my external matlab script that creates and saves the plot image I have this portion of code. It does update the image2 component insdie the GUI, but it creates a new instance of the gui instead of updating the current gui. is there a way to update the current gui instead of having to make one. I read online that the workspace doesnt see the current gui so it makes a new instance. this is the portion of the external matlab script.
% Check if the GUI instance exists
if exist('app', 'var') && isa(app, 'MotorGUI')
% Access the existing instance
else
% Create a new instance
app = MotorGUI();
end
%
% Call the updateImage function with the filename as an argument
filename = 'RatePlot060.png';
% app.updateImage(filename);
updateImage(app,filename);

Connectez-vous pour commenter.

Catégories

En savoir plus sur Images dans Help Center et File Exchange

Produits


Version

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by