How do i display output figure from m file in App Designer uiaxes?

Good Day everyone!
I am having a confusion on how to display an output figure that I run in m file, in app designer uiaxes?
Or.. Is it possible to do so?
Okay, basically i have a button in app Designer that run m. file, which has a figure output. below is a part of the m file that plot the output figure. I set the figure to global. am not sure whether it possible or not.
global K;
K = figure;
plot(Orientation_vect,TuningCurve_RateDiff_vect(1:NumAngles), 'color', 'b')
hold on
plot(Orientation_vect1,TuningCurve_RateDiff_vect1(1:NumAngles1), 'color', 'r')
xlabel('Orientation(deg)')
ylabel('Ave firing rate relative to control (Hz)')
grid on
Next, below is the code for pushed function, which I called the global value for the figure.
% Button pushed function: PercentageButton
function PercentageButtonPushed(app, event)
run comparison.m
global K;
imshow(K,'parent',app.FiringRates);
end
turns out I'm getting error this.
Error in imshow (line 245)
images.internal.imageDisplayParseInputs({'Parent','Border','Reduce'},preparsed_varargin{:});
is there anything that Ive done wrong or Is there anything i can do to improve and make this work out?
Thank you!

6 Comments

Is there more error message before that, saying what matlab thinks is wrong?
Yes. Sorry for not to put in details. Here is the earlier error messages
Error using imageDisplayValidateParams
Expected input number 1, I, to be one of these types:
numeric, logical
Instead its type was matlab.ui.Figure.
Error in images.internal.imageDisplayValidateParams (line 11)
validateattributes(common_args.CData, {'numeric','logical'},...
Error in images.internal.imageDisplayParseInputs (line 78)
common_args = images.internal.imageDisplayValidateParams(common_args);
You have
global K;
K = figure;
so global K is assigned a figure.
You have
run comparison.m
global K;
imshow(K,'parent',app.FiringRates);
if global K has not changed, then global K is still the figure and it would not make any sense to try to imshow() a figure.
Are you expecting that the script comparison.m will assign to K something that is an image? If so then does comparison.m have a global K before it assigns to K? If comparison.m assigns to K, then it would be to the local K variable, and then when you global K you would wipe out the local K variable and replace it with the global K.
Are you expecting that the script comparison.m will assign to K something that is an image?
Yes, is it possible to pass image by global the image?
If so then does comparison.m have a global K before it assigns to K?
Also yes. I already assign K as global in the comparison.m
I assign global K both in comparison.m, and also in the callbacks button. I am trying global with variables, it works that way but not sure with images.
Thus, do you have any suggestion/ways (other than using global thingy), so that I can display the output images from comparison.m in AppDesigner?
Thanks Walter!
@Fadilla Atyka Nor Rashid did you figure out what can be done. Even I have the same issue right now and it would be really useful if you could share your solution.
For most graphics calls, you can put the target axes as the first parameter of the graphics call, such as
plot(app.Axes1, rand(1,20))
hold(app.Axes1, 'on')
plot(app.Axes1, rand(1,20)*2);
hold(app.Axes1, 'off')
In most of the other graphics calls that do not accept an axes as the first parameter, you can use a 'Parent' name/value pair instead, such as
plot(rand(1,20), 'Parent', app.Axes1)

Sign in to comment.

Answers (1)

To the point.
Save figure to a file then show in App Designer.
%save figure without dispaying it in m file
f1 = figure('visible','off');
show(figureobject);
saveas(f1,'name','jpg');
%display the image file in App Designer
app.Image.ImageSource = 'name.jpg';
OK, done. I am currently also doing the same thing.

2 Comments

You can use this code for 3D plot using App designer.
data = [0:10;(0:10).^2;10:20]'; %use your own data
plot3(app.UIAxes, data(:,1), data(:,2), data(:,3), 'r-'); %adjust the UIAxes name

Sign in to comment.

Categories

Find more on Develop Apps Using App Designer in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!