Azzera filtri
Azzera filtri

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

18 visualizzazioni (ultimi 30 giorni)
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

Risposta accettata

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

Più risposte (1)

Jiri Hajek
Jiri Hajek il 14 Ott 2022
It should be sufficient to enforce update of your output using:
drawnow limitrate.
  3 Commenti
Jiri Hajek
Jiri Hajek il 17 Ott 2022
Modificato: Jiri Hajek il 17 Ott 2022
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....

Accedi per commentare.

Community Treasure Hunt

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

Start Hunting!

Translated by