How can I plot and display image in MATLAB App Designer UIAxes?

67 views (last 30 days)
I am creating a Turbocharging matching tool and an important part of this (for the user) is to see the operating points plotted on compressor maps.
The first problem I am running into is that it doesn't plot the points needed. These points should be taken from the edit fields next to 'Corr. Mass Air Flow' and 'Compressor PR' but it doesn't seem to work. The code for this part is under the callback function "MatchButton pushed".
The second problem I am facing is when I am trying to display the compressor map as an image in the background of the UIAxes. I have multiple compressor maps and I want to use a listbox along with an ifelse command to display the chosen compressor map as an image. The image does not display and the axes disappear. I attached a screenshot of what this looks like in the app itself and the image that I want displayed. The code for this is under the callback of list box value changed.
Thank you in advance!
% Button pushed function: MatchButton
function MatchButtonPushed(app, event)
x = [str2double(app.MassAirFlow1)
str2double(app.MassAirFlow2)
str2double(app.MassAirFlow3)
str2double(app.MassAirFlow4)
str2double(app.MassAirFlow5)
str2double(app.MassAirFlow6)];
y = [str2double(app.CompPR1)
str2double(app.CompPR2)
str2double(app.CompPR3)
str2double(app.CompPR4)
str2double(app.CompPR5)
str2double(app.CompPR6)];
plot(app.UIAxes,x,y, 'o');
end
% Value changed function: CompressorListBox
function CompressorListBoxValueChanged(app, event)
value = app.CompressorListBox.Value;
if strcmp(value, '62K80 (EFR 6258)')
hold(app.UIAxes, 'on')
I = imshow('62K80.jpg', 'Parent', app.UIAxes, ...
'XData', [1 app.UIAxes.Position(3)], ...
'YData', [1 app.UIAxes.Position(4)]);;
hold(app.UIAxes, 'off')
elseif strcmp(value, '67X80 (EFR 6758)')
hold(app.UIAxes, 'on')
I2 = imshow('67X80.png', 'Parent', app.UIAxes, ...
'XData', [1 app.UIAxes.Position(3)], ...
'YData', [1 app.UIAxes.Position(4)]);;
elseif strcmp(value, '70S75 (EFR 7064)')
hold(app.UIAxes, 'on')
I3 = imshow('70S75.png', 'Parent', app.UIAxes, ...
'XData', [1 app.UIAxes.Position(3)], ...
'YData', [1 app.UIAxes.Position(4)]);;
else strcmp(value, '76S75 (EFR 7670)')
hold(app.UIAxes, 'on')
I4 = imshow('76S75.png', 'Parent', app.UIAxes, ...
'XData', [1 app.UIAxes.Position(3)], ...
'YData', [1 app.UIAxes.Position(4)]);;
end

Answers (1)

Mario Malic
Mario Malic on 14 Feb 2021
Edited: Mario Malic on 10 Mar 2021
Hello,
For your first problem, use numeric Editfield components, for those you don't need to use str2double. You should've seen the error that you cannot convert EditField component to double, the values in the box can be found in property Value.
For the second one, to display the image in UIAxes component you can do it this way
cImage = imread("62K80.jpg");
hImage = imshow(cImage, 'Parent', app.UIAxes);
Edit: comment section summed up
When you use imshow, it will use the size of image (height x width x page) to plot.
im = imread('pears.png');
imshow(im, 'Parent', uiax);
Without XData and YData it will use some sort of algorithm to determine XLim and YLim that would nicely display the data in plot.
You can use this to fill the plot area
app.UIAxes.XLim = [0 width(im)];
app.UIAxes.YLim = [0 height(im)];
  11 Comments

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!

Translated by