Update Webdesigner App Image component- how??

4 visualizaciones (últimos 30 días)
Kenneth
Kenneth el 13 de Mzo. de 2024
Comentada: Kenneth el 14 de Mzo. de 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?

Respuestas (1)

Kojiro Saito
Kojiro Saito el 14 de Mzo. de 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 comentario
Kenneth
Kenneth el 14 de Mzo. de 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);

Iniciar sesión para comentar.

Categorías

Más información sobre Environment and Settings en Help Center y File Exchange.

Productos


Versión

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by