function calculate_Callback(hObject, eventdata, handles)
% hObject handle to calculate (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
acc= str2num(get(handles.a,'string')); % storing value of "a" in acc using Tag
time= str2num(get(handles.time,'string'));
inter= str2num(get(handles.inter,'string'));
wfunc=(get(handles.W,'string'))% storing value of "W" in wfunc using Tag. W is string.
[acc_rms,acc_w_t,acc_w_f,frequency]=acc_weight(acc,time,inter,wfunc);
acc_rms1=num2str(acc_rms);
acc_w_t1=num2str(acc_w_t);
acc_w_f1=num2str(acc_w_f);
frequency1=num2str(frequency);
set(handles.a_rms,'string',acc_rms1);
set(handles.a_w_t,'string',acc_w_t1);
set(handles.a_w_f,'string',acc_w_f1);
set(handles.freq,'string',frequency1);
I do not have any access to workspace in the code presented above. Can someone guide me how can I access variables from workspace and store them back to workspace?
Thanks in advance.
use evalin('base',a) to get variable a from workspace and assignin('base','a_rms',a_rms) to write variable a_rms to workspace.
Uwe
"Dharmesh Nadhe" <dharmes...@gmail.com> wrote in message <imvtm6$p4a$1...@fred.mathworks.com>...
function update_listbox(handles)
importfile('file_name')
vars = evalin('base','who');
set(handles.data,'String',vars)
After this I have all data imported in GUI with list of name of variables in slide box. To select time and a , which means, 2 vector inputs from list I have following code:
function [var1,var2] = get_var_names(handles)
list_entries = get(handles.data,'String');
index_selected = get(handles.data,'Value');
if length(index_selected) ~= 2
errordlg('You must select two variables',...
'Incorrect Selection','modal')
else
var1 = list_entries{index_selected(1)};
var2 = list_entries{index_selected(2)};
end
Now I guess I have entire input data to work with. On the basis of this data I have one push button"calculate" with tag"compute" to execute my above mentioned "acc_weight" function. Belows the callback function in my compute button, my code is as follows:
[time,acc] = get_var_names(handles); % here I am getting selected variables in time and acc and it works fine. But assigned values are only selected workspace variable names not the values of it. Then I have my other two inputs "inter" and "W" as follows:
inter1= str2num(get(handles.inter,'string'));
wfunc=(get(handles.W,'string')); % I want to read W as a string.
Now I wish to execute my function. I tried executing it as follows:
[acc_w_t,acc_w_f,frequency]=evalin('base'['acc_weight(',acc,',',time,',',inter1,',',wfunc,')']);
But it doesn't work. I gives error saying not able to read inter1 and W. So how can I write my function " acc_weight" using "evalin" ? how can I deal with non workspace inputs such as "inter1" and "W" ?
And how can I have output variables "a_rms","a_w_t","a_w_f" and "freq" back to workspace?
Thanks in advance.
if you have the variables acc, time and inter1 in the base workspace, it should work as follows:
[acc_w_t,acc_w_f,frequency]=evalin('base','acc_weight(acc,time,inter1,'''W''')');
If you want to send a variable from your GUI to the base workspace, do it like this:
assignin('base','a_rms',a_rms);
I hope this helps :-)
Uwe
"Dharmesh Nadhe" <dharmes...@gmail.com> wrote in message <in1k3g$1il$1...@fred.mathworks.com>...