How can I save my data in an array in GUI?

조회 수: 2 (최근 30일)
Ainoha Cruz Marrero
Ainoha Cruz Marrero 2017년 11월 7일
답변: Yasemin G 2021년 10월 26일
Good morning,
I am trying to do a code in GUI where I have to read some data in two differents .txt (Uc.txt and Uapp.txt) and then I have to do some calculations with this data and finally plot the results in a graphic, which is related to a checbox. The thing is when I do my code, matlab says the variable tc is not defined and I don't really understand why. My code so far is this:
function checkbox1_Callback(hObject, eventdata, handles)
% hObject handle to checkbox1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hint: get(hObject,'Value') returns toggle state of checkbox1
if get(handles.checkbox1,'Value')
aa = evalin('base','tc');
bb = evalin('base','q1');
cc= evalin('base','vapp');
handles.axes1 = plotyy(aa,bb,aa,cc);
title('Time-resolved electrical signals');
xlabel('time (s)');
ylabel('Voltage (V)');
legend('Charge signal (Qt)','High volage signal (Uapp)');
guidata(hObject,handles); % do this to save the updated handles structure
else
if ~isempty(handles.axes1)
delete(handles.axes1);
end
guidata(hObject,handles);
end
% --- Executes on button press in pushbutton1.
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)
C=22e-9;
[filename, pathname, filterindex] = uigetfile('*Uapp.txt', 'Pick a MATLAB code file');
[tapp,vapp]=textread(filename); % We define at the same time the high voltage waveform array
[filename2,pathname2, filterindex2] = uigetfile('*Uc.txt', 'Pick a MATLAB code file');
[tc,vc]=textread(filename2);
q1=vc.*C;
Qt=[tc,q1];
Is just the part in GUI I am using it, a pushbottom to load the text files and then a checkbox where if this checkbox is ticked the graph shoulkd appear, and if is not the graph shouldn't.
Thank you in advance,
Ainoha

채택된 답변

ES
ES 2017년 11월 7일
편집: ES 2017년 11월 7일
tc and q1 are not available in base workspace. So your will not work.
1. You can set tc an q1 as globals so that you can access them in other functions. or 2. Pass this data to the function. (using handles structure if you would like. Something like
[filename, pathname, filterindex] = uigetfile('*Uapp.txt', 'Pick a MATLAB code file');
[tapp,vapp]=textread(filename); % We define at the same time the high voltage waveform array
[filename2,pathname2, filterindex2] = uigetfile('*Uc.txt', 'Pick a MATLAB code file');
[tc,vc]=textread(filename2);
q1=vc.*C;
handles.tc = tc;
handles.q1 = q1;
Qt=[tc,q1];
% Update handles structure
guidata(hObject, handles);
You can use handles.tc or handles.q1 in the chekbox callback!
  댓글 수: 1
Ainoha Cruz Marrero
Ainoha Cruz Marrero 2017년 11월 7일
Thank you J Smith,
I tried what you said but in some way the code is still saying tc is undefined, even if I use handles.tc and handles.q1 in the checkbox callback. If I try to plot the graph in the pushbottom callback is working perfectly but I can not get it in the checkbox callback.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Yasemin G
Yasemin G 2021년 10월 26일
Hello Ainoha,
Can you share your .m file with me please I am having the same problem.

카테고리

Help CenterFile Exchange에서 Two y-axis에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by