- "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!