How to plot in real time the value of a variable in Matlab App Designer?

조회 수: 18 (최근 30일)
Hi everybody,
I am writing an App to make some operations on my data. I have almost finished coding the app but I met an issue. I would like to display the value of a variable insisde a for-cycle to let the user know the progress of the app analysis. I tried with EditField but it displais only the value 1 at the end of the process, whereas I want to display in real-time the value of the variable called k that keeps track of the progress of the for-cycle. Below I attach the code of interest: can anyone help me?
Thanks you in advance!
for i=1:app.le
k=i; app.EditField.Value=fprintf('%d',k) %I want to display the value of k while it increases from cycle to cycle
text=fileread(app.str(i));
text2=strrep(text,',','.');
dlmwrite(app.str(i),text2,'delimiter','');
fidi = fopen(app.str(i),'rt')
k1 = 1;
while ~feof(fidi)
readline = fgetl(fidi);
if strcmp(readline,'Results:')
C = textscan(fidi, '%f%f%f%f %*f%*f%*f%*f%*f%*f', 'HeaderLines',9, 'CollectOutput',1);
else
C = textscan(fidi, '%f%f%f%f %*f%*f%*f%*f%*f%*f', 'HeaderLines',9, 'CollectOutput',1);
end
M = cell2mat(C);
fprintf(1,'\tSection %2d: (%4d x %d)\n', k1, size(M))
if isempty(M) % Empty Matrix Indicates End-Of-File
fprintf(1,'Reading finished, %d Sections\n',k1-1)
break
end
D{k1,:} = M;
fseek(fidi, 0, 0);
k1 = k1 + 1;
end
fclose(fidi);
Dflip = flip(D); % Reverse Section Order
app.Out = cell2mat(Dflip);
un=app.Out(:,1);
t=app.Out(:,2);
T=app.Out(:,3);
Cp=app.Out(:,4);
a=find(un==0);
b=find(un==1);
if length(a)~=length(b)
unit=b;
else unit=a;
end
extr= [diff(a);length(un)-a(end)+1];
In = mat2cell(t, extr);
for j=2:length(In)
A=In{j-1,end}; AA=A(end);
In{j,:}=In{j,:}+AA;
end
time=cell2mat(In);
app.Matr=[un t T Cp time];
app.C=strcat(app.path, 'conv_', app.A(1+i));
writematrix(app.Matr,app.C,'Delimiter','tab'); app.GotonextstepLamp.Color='g';
end

채택된 답변

Daniele Sonaglioni
Daniele Sonaglioni 2022년 10월 21일
To update the value of the field while performing the for-cycle, it is enough to write:
drawnow limitrate
app.(sprintf('EditField')).Value=i

추가 답변 (1개)

Jiri Hajek
Jiri Hajek 2022년 10월 14일
It should be sufficient to enforce update of your output using:
drawnow limitrate.
  댓글 수: 3
Jiri Hajek
Jiri Hajek 2022년 10월 17일
편집: Jiri Hajek 2022년 10월 17일
It seems that something is not working as should. Did you try to debug the app using a breakpoint at the problematic line? Several things could go wrong when updating the value, which prevent the change of EditField value. You need to check if the code works properly when you go throught the process step by step. Please check that the value updates as expected when you execute the line manually....
Daniele Sonaglioni
Daniele Sonaglioni 2022년 10월 21일
I added a brekpoint but the value does not update automatically

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

카테고리

Help CenterFile Exchange에서 Develop Apps Using App Designer에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by