I'm trying to make a simple GUI with App Designer in MATLAB. I want to have a button called "Rotate 90" that will rotate 90 degrees the figure every time that is pressed. What I managed to do is to only rotate it once, but then I have the obvious problem that when pressed again, it will rotate the original picture again, instead of the new one just generated.
UIAXes is the axes where I previously showed a figure in. I have the following properties before the callbacks:
% Properties that correspond to app components
properties (Access = public)
UIFigure matlab.ui.Figure
OpenimageButton matlab.ui.control.Button
TextArea matlab.ui.control.TextArea
DropDownHistogram matlab.ui.control.DropDown
DropDownProperties matlab.ui.control.DropDown
Rotate90Button matlab.ui.control.Button
Rotate180Button matlab.ui.control.Button
UIAxes matlab.ui.control.UIAxes
UIAxes_2 matlab.ui.control.UIAxes
end
properties (Access = private)
oldpath = addpath(genpath('/Libraries/')) % Load libraries
ImageFile; % Image loaded
handlehistogram;
fullname;
degrees;
end
The callback function is as following:
% Button pushed function: Rotate90Button
function Rotate90ButtonPushed(app, event)
image90 = app.ImageFile;
rotated90 = imrotate(image90, 90);
imagesc(app.UIAxes, rotated90);
end
If anybody's interested, that's how I solved it:
I added a property called rotatedImg
properties (Access = private)
oldpath = addpath(genpath('/Libraries/')) % Load libraries
ImageFile; % Image loaded
handlehistogram;
fullname;
filename;
degrees;
rotatedImg;
end
and I wrote this in my callback function:
% Button pushed function: Rotate90Button
function Rotate90ButtonPushed(app, event)
app.rotatedImg = imrotate(app.rotatedImg, 90);
imagesc(app.UIAxes, app.rotatedImg);
end