How to plot in real time the value of a variable in Matlab App Designer?
17 views (last 30 days)
Show older comments
Daniele Sonaglioni
on 14 Oct 2022
Answered: Daniele Sonaglioni
on 21 Oct 2022
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
0 Comments
Accepted Answer
More Answers (1)
Jiri Hajek
on 14 Oct 2022
It should be sufficient to enforce update of your output using:
drawnow limitrate.
3 Comments
Jiri Hajek
on 17 Oct 2022
Edited: Jiri Hajek
on 17 Oct 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....
See Also
Categories
Find more on Develop Apps Using App Designer in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!