Defining the Parent location of a UIAxes plot

4 views (last 30 days)
Hi all,
This is a continuation of a project I'm working on that started over in [this] thread. I've created a script that generates a "moving message display" utilizing the text displays in a plot window, but now I'm taking it a step further by creating an app to house that code. I'm specifically running into a problem with trying to set the Parent location for the UIAxes plot. The app designer is throwing an error thinking that I'm trying to use the RightPanel as an index, but that's where I want the UIAxes plot to reside instead of generating in a new figure window, so I thought I needed to define the Parent location... Is there something glaringly wrong with my code?
Thanks for the help!
function RunButtonPushed(app, event)
% Gather User Inputs from Left Panel of the GUI
% Set Background and Text Colors according to the button selected by the User
bgColor = app.BackgroundColorButtonGroup.SelectedObject.Tag;
txtColor = app.TextColorButtonGroup.SelectedObject.Tag;
msg = app.MessageEditField.Value; % Set the desired Message
if isempty(msg) % If the User does not specify a message
msg = ' YOUR TEXT HERE '; % Default to display of 'YOUR TEXT HERE'
end
t = now; % Grab current system time
% Convert it to a datetime format and put that value in a string
d = string(datetime(t,'ConvertFrom','datenum'));
% Time = pad(d,2,'both'); % Pad each end of the string by two spaces
spacer = " "; % Create Spacer string for extra padding
temp = floor(1 + (46-1).*rand(1,1)); % Create random temperature value
% Concatenate all pieces in a string then convert it to a character array
display = char(strcat(spacer,msg,spacer,"Today's Date Is: ",d,spacer,"The Current Temperature Is: ",num2str(temp),char(176),"C"));
% Display the message back to the User on the UIAxes in the Right Panel
ax = app.UIAxes('Parent',app.RightPanel);
ax.Color = bgColor;
ax.Box = 'on';
hold on
for i = 1:(length(display)+1) % Loop once for length of entire message
cla(ax) % Clear previous Axes
ax = gca; % Create axis handle
ax.Color = bgColor; % Set background color of the plot window
text('Parent',ax,display,'Color',txtColor,'FontSize',72,'FontName','LED Counter 7'); % Display message as text
display = circshift(display,-1); % Circle Shift character array, Scrolling Left
i = i + 1; % Increment i
pause(0.5); % Pause for 0.5 sec
end
end
  1 Comment
Lucas Lombard
Lucas Lombard on 1 Dec 2022
Edited: Lucas Lombard on 1 Dec 2022
Update: I shifted a few things around and I think I fixed everything, though is there a way to prevent the text display from being visible outside of the UIAxes window? It's sticking out on the right side
% Display the message back to the User on the UIAxes in the Right Panel
ax = app.UIAxes;
ax.Parent = app.RightPanel;
ax.Color = bgColor;
ax.Box = 'on';
hold on
for i = 1:(length(display)+1) % Loop once for length of entire message
cla(ax) % Clear previous Axes
text(ax,0,0.5,display,'Parent',app.UIAxes,'Color',txtColor,'FontSize',72,'FontName','LED Counter 7'); % Display message as text
display = circshift(display,-1); % Circle Shift character array, Scrolling Left
i = i + 1; % Increment i
pause(0.5); % Pause for 0.5 sec
end

Sign in to comment.

Accepted Answer

Kevin Holly
Kevin Holly on 1 Dec 2022
Edited: Kevin Holly on 1 Dec 2022
remove
ax = gca; %This creates a new axis when there isn't an axis in a figure window.
Edit:
This line isn't needed in for loop:
ax.Color = bgColor;
This line doesn't need to be in for loop:
text(ax,0,0.5,display,'Color',txtColor,'FontSize',72,'FontName','LED Counter 7'); % Display message as text
Also,
ax = app.UIAxes;
ax.Parent = app.RightPanel;
ax.Color = bgColor;
ax.Box = 'on';
can be written as
app.UIAxes.Parent = app.RightPanel;
app.UIAxes.Color = bgColor;
app.UIAxes.Box = 'on';
  5 Comments

Sign in to comment.

More Answers (0)

Categories

Find more on Migrate GUIDE Apps in Help Center and File Exchange

Tags

Products


Release

R2021a

Community Treasure Hunt

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

Start Hunting!