How do I use MATLAB app designer to display a command window for my app?

I am converting a program I wrote in regular scripts to an app. I want to be able to have a window in my app that I can write data to.
I have been trying to use
fprintf(object,"Some Text\n")
I have tried using the slrealtime System Log block but I cannot print to it.
I also tried writing to a file and then pulling that back into the app at the end of execution.
I need to print text to the app somehow. How should I be attacking this.

3 Comments

If anyone has commentary on how I asked my question of wants more detail let me know, I am just a student in search of the knowledge to get through undergrad.
What is "object" in your fprintf command? An edit field is the standard to display and edit text.
I tried using
fprintf(app.SystemLog,"Text");
And then I tried a different approach
lg = fopen('Log.txt','W')
fprintf(lg,"Text")
But then I could not get the text to display in my app
I'll give an edit field a shot

Sign in to comment.

 Accepted Answer

This is "gun-shot programming". Please read the documentation:
doc fprintf
doc fopen
Both commands do not write text to a GUI element. How did you create app.SystemLog?
Does your app.SystemLog has a property called "Value"? Try
app.SystemLog.Value = "Hello"

5 Comments

Update
SystemLog is unique to simulink real-time it does not have property value, I was, admittedly foolishly, trying to shoehorn my command window output into this simulink real-time object.
I came up with a functional solution, albeit not vert elegant:
using a text box element named TextArea_2
defined as:
TextArea_2 matlab.ui.control.TextArea
I added a property to store my strings, under public properties of my app class
outText = [];
I created this function:
% APPLOGGER.m
% Thomas Cote
% Created: 03/16/22
% Umass Lowell - EECE.2080 - Basic EE lab II
%
% handles text output for matlab app
%
function AppLogger(app,string)
app.outText = [app.outText; sprintf(string)];
app.TextArea_2.Value = app.outText;
end
and I called this function as:
AppLogger(app,"Analyzing Data.....")
This has been working out for me. The peice I was missing was that I did not understand which app designer elements I should be using. a Text Area element worked much better than a System Log or an Edit Field.
Hope this helps :)
Also, I could not find a defintion for "Gun-Shot Programming" anywhere, would you mind explainging or linking me to a definition.
You find a list of anti patterns here: https://en.wikipedia.org/wiki/Anti-pattern
fprintf(app.SystemLog,"Text");
Here the shotgun style is to choose fprintf because the name sounds like something, which culd solve the problem. But takeing a look into the documentation reveals directly, that this is not matching.
Writing the text to a file andhoping tofind a method to insert the file's contents in a GUI element, is an XY-problem.
Hey! I need to update a terminal UI element from guide to appdesigner. It includes a command box for user input. Do you have a way to allow for input?
Preferably avoiding eval statements to avoid exploits in security
Hi Tom, just want to give you a credit for the simple solution that you have!
Thank you a lot!
Sincerely,
Huy

Sign in to comment.

More Answers (0)

Categories

Products

Release

R2022a

Asked:

on 16 Mar 2022

Moved:

on 5 Feb 2025

Community Treasure Hunt

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

Start Hunting!