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
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...
César Hernández
I hope you are better about the news in Texas. We have to assimilate it.
Well, on the other hand, I suppose there are probably some ways to do it.
Allow me explain you please: let's see if I understand; the code works for me, and you can confirm it by creating a figure with one plot and a numbered name, in my case papo1. Then save it in a file with fig extension, use savefig. You only need 3 or 5 lines of code before the published code, and aro or i become = 1. Let's see, this is more or less like this: What I'm going to do is that if before the last end you apply a waitfor and break with Ctrl + Break, I don't know if I'm wrong but B1 becomes registered in the base or current workspace as a variable of type figure 1 * 1. The point is that already the variable identified in the workspace allows to the activity access the all properties hyperlink pseudocode and read the variable, so, It seems could run the pseudocode. Perhaps I'm wrong or I'm not located, but if you understand my request and you could please help me, I would appreciate it again.
Well, it's not my field, but, (i don't know if i'm wrong), What i mean is that assignin and evalin whether 'base' or 'caller' both, during the program running, both are working in a 'caller' and not 'base' workspace. So, when the program and its activities are over, if assignin and evalin are 'base', both adds the variables to base or current workspace.
Hey, Im a little late !!! Let me say; what I mean is I don't pretend to break the quantity of that kind variables in matlab. It is a bit murky for me. But you can barely, maybe you can help me about this process PLEASE... I need clarity and a bit of simplicity about your views and analysis. I think Matlab is able to do that process, to spare ... Thank you !!!

请先登录,再进行评论。

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Environment and Settings 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by