GUI_1.get string from edit box 2.load .mat which has same name with string input
11 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
MINKYUNG KIM
am 9 Dez. 2018
Kommentiert: MINKYUNG KIM
am 10 Dez. 2018
HI. I'm designing a gui.
I'm using r2018a and guide.
I want to input a string, which is a person's name, into a edit1 box, and then display that string on the edit2 box.
And I finally want to load .mat file named the string that I entered in edit1 box.
I can input a string and display, but I got error message on load.
Error code said, ' load should be string arrays or character arrays.'
function pushbutton1_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
user_name = get(handles.edit1, 'String');
set(handles.edit2, 'String', user_name)
user_data = load(user_name); %user_name is string type, right? what's the problem?
plot(handles.axis1, user_data)
Plz give me some advice. Appreciate in advance ;)
0 Kommentare
Akzeptierte Antwort
Geoff Hayes
am 9 Dez. 2018
I've found that sometimes with code like
user_name = get(handles.edit1, 'String');
user_name is a cell array (with one string element) and so is not a character array. What you may have to do here is to convert this into a string with char as
user_data = load(char(user_name));
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Characters and Strings finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!