HOW CAN I GET THE VALUE OF A VARIABLE OF A FUNCTION FILE TO USE IT IN OTHER FUNCTION FILE?

1 次查看(过去 30 天)
%I attached the files a created.. I want to use the value of the variable 'density' to use it in the file report1.m

采纳的回答

Walter Roberson
Walter Roberson 2015-7-31
You do not have a variable named "density". You have a text field that contains the word DENSITY and you have an edit field that you store values in as a string.
What you would do is use pass the handle of the first figure into guidata() to retrieve the handles structure belonging to the first figure, and then
str2double( get(handles.edit3, 'String') )
would get you the numeric equivalent of the field.
But inside REPORT1 you do not normally know what the figure handle is for the figure for PROG1. So you have to find it:
prog1_fig = findall(0,'NAME','PROG1');
prog1_handles = guidata(prog1_fig);
prog1_density_handle = prog1_handles.edit3;
report1_fig = findall(0,'NAME', 'REPORT1');
report1_handles = guidata(report1_fig);
report1_density_handle = report1_handles.edit1;
prog1_density_string = get(prog1_density_handle,'String');
set(report1_density_handle, 'string', prog1_density_string);

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 String Parsing 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by