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

조회 수: 11 (최근 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