How can I save my data in an array in GUI?
조회 수: 1 (최근 30일)
이전 댓글 표시
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
댓글 수: 0
채택된 답변
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개)
Yasemin G
2021년 10월 26일
Can you share your .m file with me please I am having the same problem.
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Two y-axis에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!