Waitbar does not increment

6 vues (au cours des 30 derniers jours)
Richard
Richard le 10 Déc 2011
I am trying to use waitbar to show the progress of a for loop that is stepping through a data file using memmapfile and doing array arithmetic on the data. The bar remains at 0 until the loop exits and then jumps to full scale in one jump. I have tried adding a refresh or a drawnow following the waitbar update with no success. I have run the approxpi example from help and that runs correctly. The loop, which works correctly, looks like this: (somewhat simplified, leaving out the array definitions and the full table structure)
Previous_Frequency = 0;
Current_Frequency = 0;
Data_Offset = PCT_Count + (4 * Echo_Count); % total size of pulse table and data block in bytes
hwb = waitbar(0, 'Getting the data, Please wait');
j = ones(1, 1,'int32'); % new frequency counter
for p = 1 : Total_pulse_Count
waitbar(p / Total_pulse_Count, hwb);
Byte_Offset = PCT_Offset + ( (p - 1) * Data_Offset);
PCT = memmapfile (Full_Name, 'Offset', Byte_Offset, 'Repeat', 1, 'Format', {
'int32' [1 1] 'record_id' ;
%etc etc
}); % Format and object end. Length 144 bytes
PCT_Data = memmapfile (Full_Name, 'Offset', Byte_Offset + PCT_Count, 'Repeat', 1, 'Format', {
'int16' [2 eval(num2str(Num_Receivers)) eval(num2str(Num_Gates))] 'IQRxRG'
}); % Format and object end.
TempIQ = PCT_Data.Data(1).IQRxRG; % read the data into memory for faster access
TempIQ = swapbytes(TempIQ);
Current_Frequency = PCT.data.frequency;
if p == 1 % special case, first loop
Previous_Frequency = Current_Frequency;
Frequency_Scale(j, 1) = PCT.data.frequency;
end
if Current_Frequency ~= Previous_Frequency % increment the new frequency counter, update Frequency Scale
j = j + 1;
if j > Frequency_Count, break, end
Frequency_Scale(j, 1) = PCT.data.frequency;
end;
for m = 1 : Num_Receivers;
for k = 1 : Num_Gates % integrate each signal and calculate the magnitude for each antenna
if Current_Frequency ~= Previous_Frequency % start a new integration
Plot_Data_Ant(k, j - 1, m) = (I(k, m)^2 + Q(k, m)^2)^0.5; % Write the earlier loop data
I(k, m) = (TempIQ(1,m,k));
Q(k, m) = (TempIQ(2,m,k));
IT(k, j) = IT(k, j) + I(k, m);
QT(k, j) = QT(k, j) + Q(k, m);
else
I(k, m) = I(k, m) + (TempIQ(1,m,k));
Q(k, m) = Q(k, m) + (TempIQ(2,m,k));
IT(k, j) = IT(k, j) + (TempIQ(1,m,k));
QT(k, j) = QT(k, j) + (TempIQ(2,m,k));
end
end
end
for k = 1 : Num_Gates % calculate the magnitude for all the antennas
Plot_Data_All(k, j) = (IT(k, j)^2 + QT(k, j)^2)^0.5;
end
Previous_Frequency = Current_Frequency;
end;
Plot_Data_Ant(k, j, m) = (I(k, m)^2 + Q(k, m)^2)^0.5;
close(hwb);
  1 commentaire
Walter Roberson
Walter Roberson le 10 Déc 2011
Why are you using
[2 eval(num2str(Num_Receivers)) eval(num2str(Num_Gates))]
instead of the much more straight-forward
[2 Num_Receivers Num_Gates]
??

Connectez-vous pour commenter.

Réponses (2)

Fangjun Jiang
Fangjun Jiang le 10 Déc 2011
Inside the for-loop, can you try adding either "drawnow" or "pause(0.2)" after the waitbar() statement?
I never had problem regarding updating the waitbar figure. Maybe you can comment out some of the code inside the loop to see what happens.
  4 commentaires
Walter Roberson
Walter Roberson le 11 Déc 2011
Ah... I just remembered -- doesn't waitbar() have a rate limiter built in, so that it only updates every second or two? Stores the elapsed time as a property of the waitbar patch, and only updates the patch if enough time has passed ?
If my memory is correct, then waitbar() would not increment for any sufficiently fast (total time) loop.
Fangjun Jiang
Fangjun Jiang le 11 Déc 2011
I don't see a rate limit. It definitely can update much faster than every second. I've had waitbar progress continuously as fast as you pour coffee to a cup.
On the other side, it can not be due to that the OP's loop is too fast. Run the bare waitbar() below will see a nice progress.
%%
h=waitbar(0,'progress');
for k=1:1000
waitbar(k/1000,h);
end

Connectez-vous pour commenter.


Daniele Finazzi
Daniele Finazzi le 24 Oct 2022
This question is quite old, but since I have recently had the same issue, here is how I fixed it.
My guess is that Matlab performs an integer division in the first argument of the waitbar, which then results in either 0 (0%) or 1 (100%). In my case, I displayed the percent progress on the waitbar like this (using the code above as an example):
waitbar(p / Total_pulse_Count, hwb, sprintf('%d%%', p*100/Total_pulse_Count));
and I noticed the bar was on 0 until 50% was reached, and after that it jumped straight to "full scale".
So I just forced the division inside the waitbar function to be non-integer:
waitbar(double(p) / double(Total_pulse_Count), hwb);
What I don't know is why this happens in some cases only. Up until now I had been using the waitbar in the same way without ever running into this issue.

Catégories

En savoir plus sur App Building dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by