필터 지우기
필터 지우기

close figure: return value

조회 수: 5 (최근 30일)
piero
piero 2023년 6월 22일
편집: piero 2023년 6월 25일
HI, i want to know when i figure is close
(here an example no sense)
clear all
f = figure;
for c=1:100
%%do something
c
end
if c
close(f);
end
if f is close
%do something
end

답변 (2개)

dpb
dpb 2023년 6월 22일
편집: dpb 2023년 6월 23일
Use isvalid
hF=figure;
isvalid(hF)
ans = logical
1
delete(hF)
isvalid(hF)
ans = logical
0
exist('hF','var')
ans = 1
clear hF
exist('hF','var')
ans = 0
Or, put the reference to the figure inside a try...catch...end structure.
  댓글 수: 1
piero
piero 2023년 6월 23일
편집: piero 2023년 6월 23일
txk but i don't resolve my problem...
i write a piece of code:
function T=CaricaListaStrategie_Struct2(Sis)
for i=1:length(Sis)
if i==1
vv=figure(); %%it's an example but i used countodown timer
end
%% filled the array
end
close(vv);
T = cell2table(ls );
end
end
function startupFcn(app, setting)
T=CaricaListaStrategie_Struct2(setting);
app.UITable.Data=T;
end;
I want to draw the figure 'vv' but when I close it I want it to create table T (app.UITable.Data=T) Instead I see that while figure "F" is closing, it creates the table for me (not after but during)
i read this post:
but i don't know how can apply it in app designer

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


dpb
dpb 2023년 6월 23일
편집: dpb 2023년 6월 23일
vv=figure(); %%it's an example but i used countodown timer
What for? and without knowing what that was set for and what its callback is, nothing can say about what effect, if any it may be having.
But, timers are asynchronous as the reference article explains, the rest of the code goes on until the event is triggered.
I'd venture a guess the timer isn't needed here; what you're needing is simply a delay between the close function before the code proceeds to display the table...
function startupFcn(app, setting)
DURATION = 0.5; % DELAY (sec) before subsequent code executes
hF=figure();
% do whatever here w/ figure, data
ls=...; % fill the array
T = cell2table(ls);
close(hF);
START_TIME = tic(); % start delay
while toc(START_TIME)<DURATION, end % spin in place DURATION sec
app.UITable.Data=T; % and then display the table component
end
You'll have to empirically determine how long the delay needs be...to use a timer, the callback for it would have to be the line that displays the table
  댓글 수: 17
dpb
dpb 2023년 6월 25일
I thought you said it was taking 10 sec or longer to read with your looping code; that's why you were in the morass of trying to add homegrown progress bars, having timing issues and graphics display problems????
I was/am recommending you should take the above code and put it into a callable function and replace the looping structure with it and see if that isn't fast enough you can get rid of all the rest and get on to the rest of the problem.
As another alternative on how to show the user something is happening, I have a couple apps that take a while that otherwise user can't tell anything is happening -- instead of a progress bar with an unknown time, I simply create a text box and every so often when a piece of code finishes and starts the next operation, it writes a "Processing This Part..." message...that updates every so often, just enough to let the user know that the code is alive and well...here you could put it in between each of the variables; but I'm guessing it's fast-enough now that it would just flicker on the screen.
piero
piero 2023년 6월 25일
편집: piero 2023년 6월 25일
the code where I actually asked for help (I did it some time ago and I didn't remember that what takes time is reading the .txt file)(%[~,Sis]=CaricoSistemi2_Struct(Settings);) I put the counter inside this and fix it. The counter is used in the record reading phase, not in processing which is fast.
I apologize for the confusion I made
Anyway, now the problem is solved thanks

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

카테고리

Help CenterFile Exchange에서 Characters and Strings에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by