フィルターのクリア

Info

この質問は閉じられています。 編集または回答するには再度開いてください。

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

1 回表示 (過去 30 日間)
Luffy
Luffy 2015 年 11 月 3 日
閉鎖済み: MATLAB Answer Bot 2021 年 8 月 20 日
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 件のコメント
Stephen23
Stephen23 2015 年 11 月 3 日
編集済み: Stephen23 2015 年 11 月 3 日
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.

回答 (0 件)

この質問は閉じられています。

Community Treasure Hunt

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

Start Hunting!

Translated by