Update Webdesigner App Image component- how??

4 Ansichten (letzte 30 Tage)
Kenneth
Kenneth am 13 Mär. 2024
Kommentiert: Kenneth am 14 Mär. 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?

Antworten (1)

Kojiro Saito
Kojiro Saito am 14 Mär. 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 Kommentar
Kenneth
Kenneth am 14 Mär. 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);

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Images finden Sie in Help Center und File Exchange

Produkte


Version

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by