- "5*10^(-3)" consumes processing time, but replies the same value as "5e-3".
- Another magic programming example: str2num(['single(',str20,')'])|This is safer and faster: |single(str2double(str20))
- Storing data by set(0, 'UserData') is like a global variable without a name. If you run another instance of the GUI or use this technique in different GUIs, unexpected and unpredictable results will appear. It would be much safer to store the values in the GUIs UserData, or by setappdata in the root object with a name.
Update values in a vector
2 ビュー (過去 30 日間)
古いコメントを表示
hi, i want to update values in a vector but i don't know why, i'v this:
a=[5*10^(-3),0,1.6,10,-1.5,1*10^(-5),-1*10^(-3),1*10^(-6)]
b=[5*10^(-2),0.01,5,25,0.5,1*10^(-3),-1*10^(-5),-1*10^(-5)]
save('var_inic.mat','a')
evalin('base','load(''var_inic.mat'')');
load ('var_inic')
my script need to use those values in a and b even though the user don't input any value.if the user want to input values it has a editbox that saves the value:
function [] = E42_call(src,evendata)
% Callback for secondary GUI editbox.
S = get(0,'userdata');
str20=get(src,'string');
if (isempty(str2num(str20)))
set(src,'String','0')
errordlg('Por favor só numeros','Erro','modal')
else
e42 = str2num(['single(',str20,')']);
save e42
set(S.ed5max,'string',get(gcbo,'string')) % atribui a string inserida na editbox no main
end
i want to update the any value in a or b with the value of e42, same with other variables
0 件のコメント
回答 (1 件)
Jan
2011 年 10 月 20 日
The method to poof variables into the base workspace using EVALIN is prone to errors. Using a and b inside your script without defining them as inputs might seem to be an easy way, but as you see, it causes problems such that posting them in a forum is required.
Modifying the value of variables without a direct interaction will impede the debugging of your program dramatically. I strongly recommend to avoid such magic programming technique.
Some other remarks:
参考
カテゴリ
Help Center および File Exchange で Startup and Shutdown についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!