unable to see variable in workspace.it only displays in command window.

조회 수: 8 (최근 30일)
Hi, My code have 10 functions ..I am trying to save some variable in work space but itsaves only in command window.Please help me in this regards.
below piece of code is in one function..when i fix time to main function .I dont know how many times it is called.I want to store the value of "min_comp_op" every time.
for j=1:10
for i= 1:5
Id5(i)=i.*(w(i).^2)+(i+5).*(w(i+5).^2);
Id5(i);
tem=i.*(w(i).^2)+(i+5).*(w(i+5).^2);
sumc=sumc+tem;
end
ttl=sumc;
comb_ttl(j)=ttl;
end
comp_op=min( comb_ttl);
min_comp_op=comp_op;
min_comp_op;
end
Thanking You, Sita
  댓글 수: 1
TAB
TAB 2012년 6월 12일
Variables can not be saved in Command window.
Your question question is incomplete. Please explore your question and add some lines of code (how you are saving variables) to make it meaningful.
See
http://www.mathworks.com/matlabcentral/answers/6200-tutorial-how-to-ask-a-question-on-answers-and-get-a-fast-answer

댓글을 달려면 로그인하십시오.

채택된 답변

TAB
TAB 2012년 6월 13일
The scope of variables defined in the function is limited to that function only. Function variable will be deleted every time function is completed the execution and exited. So they will not appear in Workspace window.
See Base and Function Workspaces and other good reference here.
To save the function variable to base workspace use assignin() and evalin().

추가 답변 (1개)

sita
sita 2012년 6월 13일
Is there any other way to do this,i tried using assignin()
for j=1:10
for i= 1:5
Id5(i)=i.*(w(i).^2)+(i+5).*(w(i+5).^2);
Id5(i);
tem=i.*(w(i).^2)+(i+5).*(w(i+5).^2);
sumc=sumc+tem;
end
ttl=sumc;
comb_ttl(j)=ttl;
end
comp_op=min( comb_ttl);
min_comp_op=comp_op;
min_comp_op;
assignin('base','min_comp_op',val)
it gives below error. Please help if i am using it wrongly
?? Undefined function or variable 'val'.
Error in ==> evaluate_objective at 57
assignin('base','min_comp_op',val)
Error in ==> initialize_variables at 55
f(i,M + 1: K) = evaluate_objective(f(i,:));
Error in ==> nsga_2 at 62
chromosome = initialize_variables(pop);

카테고리

Help CenterFile Exchange에서 Workspace Variables and MAT Files에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by