figures and activities through workspaces.
1 次查看(过去 30 天)
显示 更早的评论
Hello and greetings to all !!!
It's not that urgent, but I'm needing it.
A query: Let's see if you can locate me: According to the code segment presented below, as indicated, I need to pass the figure variables B1, B2, B3, ..., Bn into base or current workspace, but immediately , that is, before the program code (function) last end. I have researched and it occurs to me to use export_fig or make a callback, but I need a more simply structured example to eventually understand the operation of the callback, to see if it works for me.
It is worth mentioning that at least several matlab users realize that during the execution or program code (function) run, the output variables are registered in the base or current workspace when the development of its activities ends, that is, at the last end of the program code (function ), but, that works very well, however, what I pursue and pretend is not to wait at the end, but to verify that it does so immediately during execution in the exposed code segment, or specifically, one segment activity of program below exposed.
Let's see, what occurs to you or what would you recommend for helping me ?
Whether restless to you or not. Thanks to all in advance !!!
% Many lines before this activity, that is, others activities above.
while true
prompt='Desea ver el o los gráfico(s) resultante(s) (si/yes/no). : '; % Do you wish to see the graph (yes/yes/no) ?
lo=input(prompt, 's');
lo=strtrim(lo);
if strcmpi(lo,'si') | strcmpi(lo,'no') | strcmpi(lo,'yes')
clc
break;
elseif strcmpi(lo,'')==1 | strcmpi(lo,'si')==0 || strcmpi(lo,'no')==0 || strcmpi(lo,'yes')==0
clc
display ('La respuesta debe ser si o yes o no.'); % The answer have to be yes or yes or no.
end
end
si=1;
yes=2;
no=0;
lo=subs(lo);
if lo==1 | lo==2
for i=aro % aro is a growing vector: [1 2 3 4 5,...,n]
if lo==1
fig2=openfig(sprintf('papo%d.fig',i),'reuse');
B.(genvarname(['B' num2str(i)])) = fig2;
b = getfield(B,['B' num2str(i)]);
assignin('base',['B' num2str(i)],b);
openvar(['B' num2str(i)])
% I SUPPOSE IS HERE WHERE I NEED YOUR HELP AND POINT OF VIEW. PLEASE !!!
evalin('base',['B' num2str(i)]);
G(i)=arrayfun(@getframe,[B.(['B' num2str(i)])],'un',0);
F(i)=cell2mat(G(i));
else % Thi is only for invisible fig, the point of view is above this 'else'
fig2=openfig(sprintf('papo%d.fig',i),'invisible');
B.(genvarname(['B' num2str(i)])) = fig2;
b = getfield(B,['B' num2str(i)]);
assignin('caller',['B' num2str(i)],b);
evalin('caller',['B' num2str(i)])
workspace
G(i)=arrayfun(@getframe,[B.(['B' num2str(i)])],'un',0);
F(i)=cell2mat(G(i));
end
end
B
end
% Many lines after this activity, that is, others activities below.
2 个评论
Walter Roberson
2019-8-4
Is there a reason to continually calculate ['B' num2str(i)] when you could do that once and assign it to a variable ?
openvar(['B' num2str(i)])
That is not a variable that exists in the current workspace. I know that "help openvar" says that openvar works on the base workspace, but this incorrect: openvar works on the current workspace.
evalin('base',['B' num2str(i)]);
What is the point of that? Evaluating a figure just displays figure properties, but you have the ; so you are supressing display.
fig2=openfig(sprintf('papo%d.fig',i),'reuse');
B.(genvarname(['B' num2str(i)])) = fig2;
In the case of a letter followed by a series of digits, genvarname is not going to change the character vector -- not unless the number requires more than 63 digits (in which case the variable name would be too long for a variable name.) So genvarname(['B' num2str(i)]) is going to be the same as ['B' num2str(i)] .
b = getfield(B,['B' num2str(i)]);
You assigned fig2 into that field, so there is no point recalling it back: it is still going to be fig2 . Unless, that is, genvarname gave a result different from ['B' num2str(i)], in which case the field would not exist and you would get an error...
回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Environment and Settings 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!