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

采纳的回答

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
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