-file display.m-
TYPE1 = {'AUDI','MARIA OWN THIS GREAT CAR'};
selectedCar = handles.popupmenu1.Value;
switch selectedCar
case 2
owners = TYPE1;
end;
-file modify.m-
here i have a pop up and an edit text
How cand I call variable TYPE1 from file display.m, display it on edit text and after that re writing it back to same variable on display.m
Thank you!

3 commentaires

Geoff Hayes
Geoff Hayes le 17 Mai 2022
@Cristian Martin - how are the display.m and modify.m files related to your GUI? Are they scripts or functions that you want to call from the GUI? Please clarify the flow. Also please confirm if you are using GUIDE (I think you are).
Cristian Martin
Cristian Martin le 17 Mai 2022
@Geoff Hayes those two.m files are script files made by automatically by GUI. I want to call the text generated in an edit text box by a function in a pop-up menu from first file in another edit text box file and modify and save in a first file. I hope I mede my self clear. If not please let me know. Thanks
Geoff Hayes
Geoff Hayes le 17 Mai 2022
@Cristian Martin - can you show some of the code or post the two files? I'm just curious as to what data is being written to these files. It may be simpler to just keep the data (that is written to the file) as a variable/property of the handles struct so that you don't have to open the file to read the contents just to write to the edit text control. Unless you are allowing the user to write data to the file via the GUI

Connectez-vous pour commenter.

 Réponse acceptée

Mitch Lautigar
Mitch Lautigar le 17 Mai 2022

0 votes

When you call an edit text box, the user inputs some text which will then save. If it is a popup window you are using, you should be able to get the outputs from the user. If this is a popup window in the GUI itself, the value you are looking for will look like "handles.popup1.String"

6 commentaires

Cristian Martin
Cristian Martin le 17 Mai 2022
Modifié(e) : Cristian Martin le 17 Mai 2022
Yes but this pop-up is in another file. Question was how do I call this from another file
Mitch Lautigar
Mitch Lautigar le 17 Mai 2022
Ah, so you are trying to pass the string out. You've got two options.
In the gui in the seperate folder, you can take the gui output function and pass the string out to the other gui using "varargout{1} = ..."
OR
You can use setappdata/getappdata. This looks like:
In popup window gui: setappdata(0,'user_str_input',user_str_input');
in your main gui: user_str_input = getappdata(0,'user_str_input');
Cristian Martin
Cristian Martin le 17 Mai 2022
In other way
function popupmenu1_Callback(hObject, eventdata, handles)
TIP1 = {'AUDI','ITS A GREAT CAR'};
TIP2 = {'SKODA','ITS A USUAL CAR'};
selectedCar = handles.popupmenu1.Value;
switch selectedCar
case 2
owners = TIP1;
case 3
owners = TIP2;
end
str = [];
for k = 1 : length(owners)
str = fprintf('%s\n%s', str, owners{k});
end
handles.edit1.Max = 2;
handles.edit1.String = owners;
If I select AUDI it swhows the value from TIP1
How can I modify the text directly from edit text box and save the new value trough a pushbutton function?
I tried this way but doesnt work
function pushbutton6_Callback(hObject, eventdata, handles)
intraretext = handles.popupmenu1.Value;
switch intraretext
case 2
prompt = {'Insert data:'};
dlgtitle = 'Add';
dims = [10 100];
definput = {''};
answer = inputdlg(prompt,dlgtitle,dims,definput);
assign('base','TIP1', answer);
end
Mitch Lautigar
Mitch Lautigar le 17 Mai 2022
%save the following in the initialization of the function
TIP1 = {'AUDI','ITS A GREAT CAR'};
setappdata(0,'TIP1',TIP1); %save data to MATLAB RAM.
TIP2 = {'SKODA','ITS A USUAL CAR'};
setappdata(0,'TIP2',TIP2); %save data to MATLAB RAM.
function popupmenu1_Callback(hObject, eventdata, handles)
TIP1 = getappdata(0,'TIP1');
TIP2 = getappdata(0,'TIP2');
selectedCar = handles.popupmenu1.Value;
switch selectedCar
case 2
owners = TIP1;
case 3
owners = TIP2;
end
str = [];
for k = 1 : length(owners)
str = fprintf('%s\n%s', str, owners{k});
end
handles.edit1.Max = 2;
handles.edit1.String = owners;
------------------------------------------------------------------------
function pushbutton6_Callback(hObject, eventdata, handles)
TIP1 = getappdata(0,'TIP1');
intraretext = handles.popupmenu1.String;
TIP1 = [handles.listbox.String(value);intraretext]
%value is whatever the value selected is from the dropdown list.
setappdata(0,'TIP1',TIP1)
Should get you going once you play with it.
Cristian Martin
Cristian Martin le 18 Mai 2022
Thank you Mitch Lautigar
Cristian Martin
Cristian Martin le 18 Mai 2022
Error using subsindex
Function 'subsindex' is not defined for values of class 'cell'.
Error in test>pushbutton6_Callback (line 784)
TIP1 = [handles.edit1.String(TIP1);intraretext];
Error in gui_mainfcn (line 95)
feval(varargin{:});
Error in test (line 42)
gui_mainfcn(gui_State, varargin{:});
Error in @(hObject,eventdata)test('pushbutton6_Callback',hObject,eventdata,guidata(hObject))
Error while evaluating UIControl Callback
?

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

Produits

Version

R2015a

Community Treasure Hunt

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

Start Hunting!

Translated by