GUI_1.get string from edit box 2.load .mat which has same name with string input

12 次查看(过去 30 天)
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 ;)

采纳的回答

Geoff Hayes
Geoff Hayes 2018-12-9
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));
  1 个评论
MINKYUNG KIM
MINKYUNG KIM 2018-12-10
Wow amazing Thanks I solved problem
user_data = load(char(user_name));
or
user_data = load(string(user_name));
It works well.
I'm a begginer so I always miss that kind of small detail.
Thank you for your advice

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Characters and Strings 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by