Display outputs of Program in AppDesigner

8 views (last 30 days)
Mert Gurer
Mert Gurer on 4 Oct 2021
Answered: Shanmukha Voggu on 27 Oct 2021
Hello,
I have a main Program "main2" for some calculation.
The results of this Program are three arrays:
First array "output" is a 1x4 string
Second array "output2" is a 1x2 double
Third array "gg" is a 1x1 double
I want to display these results in my App in Appdesigner (in different Editfields). E.g. output(1,1) in Editfield1
How can I do this?
My current App is pretty basic and the Callbacks and StartupFunction contain just some tries which are commented out.
Thank you.
M.

Answers (1)

Shanmukha Voggu
Shanmukha Voggu on 27 Oct 2021
Hi Mert,
The Problem can be solved by two ways as mentioned below:
1) Manually create all the required EditFields in the design view of the app, name them and assign values
app.EditField.Value=output(1,1);
app.EditField.Value=output(1,2);
% and so on, This can be useful when you have small and fixed size output
% arrays from main2 function
2) If the outputs of the function vary in size dynamically, then the following process is recommended
Let's have an arbitrary main2 function in the same folder where the app is created or in MATLAB Path
function [output,output2,gg] = main2()
% outputs of the function main2
output=["stringOne","stringTwo","stringThree","stringFour"];
output2=[23,65];
gg=76;
end
Update the startup function of the app as follows
function startupFcn(app)
[output,output2,gg] = main2();%call to main2 function that must be in MATLAB path
%dynamically creating the EditFields in every iteration of the
%below loops
for i=1:length(output)
uieditfield(app.UIFigure,'Position',[0,i*30,100,25],"Value",output(i));
%updating position of the EditField according to the
%iteration and value is set according to the array contents
end
for i=1:length(output2)
uieditfield(app.UIFigure,'Position',[125,i*30,100,25],"Value",num2str(output2(i)));
end
for i=1:length(gg)
uieditfield(app.UIFigure,'Position',[250,i*30,100,25],"Value",num2str(gg(i)));
end
end
The app looks like as follows:
The ideal way to achieve the goal is to use TextArea component for it to reliably display the array.
Refer to this for more information.

Products

Community Treasure Hunt

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

Start Hunting!