GUI_1.get string from edit box 2.load .mat which has same name with string input
11 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
MINKYUNG KIM
le 9 Déc 2018
Commenté : MINKYUNG KIM
le 10 Déc 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 commentaires
Réponse acceptée
Geoff Hayes
le 9 Déc 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));
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Characters and Strings dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!