Repeated scalar entries to a gui edit box should be stored in an array/vector format
Info
This question is closed. Reopen it to edit or answer.
Show older comments
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 ?
1 Comment
Passing values using evalin and assignin is a buggy way to program. Learn how to pass variable properly and your code will be much neater, faster to run, and easier to debug.
Answers (0)
This question is closed.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!