How can I save my data in an array in GUI?
4 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
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 Commenti
Risposta accettata
ES
il 7 Nov 2017
Modificato: ES
il 7 Nov 2017
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!
Più risposte (1)
Yasemin G
il 26 Ott 2021
Can you share your .m file with me please I am having the same problem.
0 Commenti
Vedere anche
Categorie
Scopri di più su Whos in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!