Info

此问题已关闭。 请重新打开它进行编辑或回答。

Repeated scalar entries to a gui edit box should be stored in an array/vector format

1 次查看(过去 30 天)
In my gui,i have a popup menu where the user selects size of array.In the edit box below there is an edit box in which user enters a scalar entry & presses enter,then the next entry that he types at that edit box should be stored as 2nd entry of a vector & so on.
Example:-
  • If user enters 100 at editbox --- array value = [100]
  • next user enters 200 at editbox --- array value = [100 200]
  • ....so on.
  • If user exceeds size as set in popup --- array value = [].
My code:-
% At gui opening function:-
assignin('base','i',1);
assignin('base','array',[]);
%-------other part of code-----
% at editbox callback function
i = evalin('base',i);
array = evalin('base','array');
size = get(handles.popup1,'User Data'); % reads size of array to be set from popup menu
if length(array) < size
array(i) = str2double(get(hObject,'String'));
i = i+1;
assigin('base','i',i);
assigin('base','array',array);
else
assigin('base','array',[]);
assigin('base','i',1);
errordlg('Size Exceeded','Error');
end
Is there any better way to do this ?Without referencing to the base workspace each time ?

回答(0 个)

此问题已关闭。

Community Treasure Hunt

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

Start Hunting!

Translated by