paulo-fernando-silva / vscOctaveDebugger

MIT License
35 stars 4 forks source link

cant show any plot #45

Closed VictorGerin closed 3 years ago

VictorGerin commented 3 years ago

If a try show a plot i cant, because i cant use pause or input and if a does the plot crashes

paulo-fernando-silva commented 3 years ago

HI, can you post a simple sample that reproduces this issue? Thanks

VictorGerin commented 3 years ago

of course first a small video and i will share my code and my data file

https://user-images.githubusercontent.com/12161688/111500731-10c6c800-8723-11eb-8f13-c021e233ca82.mp4

Teste_rapido_final.zip

` clear all; close all; clc; pkg load signal;

C:\Users\victo\OneDrive\�rea de Trabalho\signal.csv

fid = fopen ('C:\Users\victo\OneDrive\�rea de Trabalho\signal.csv', 'r')

divisor = 40; Fs = 5e6 / divisor; M = dlmread('Teste_rapido_final.csv',';',2,0);

tempo = decimate(M'(1, :)', divisor) ; voltage = decimate(M'(2, :)', divisor) ;

M = 5; voltageFiltrado = filter((1/M)*ones(1,M),[1 zeros(1,M-1)], voltage);

a = 0.5;

m = 5;

voltageFiltrado = ((1-a)/(1-a*voltage^-1) )^m

figure;

subplot(2, 1, 1); [ax, h1, h2] = plotyy( tempo, voltage, tempo, voltageFiltrado );

set(ax(1),'YLim',[-10 10]) set(ax(2),'YLim',[-10 10])

figure;

Nfft = length(tempo); fvec = (-Nfft/2 : Nfft/2 - 1) * Fs / Nfft; fvec = fvec'; Xreal = fftshift( fft(voltageFiltrado, Nfft) );

[a, b] = max( abs (Xreal) );

fvec(b)

subplot(2, 1, 2); plot( fvec, 20*log10(abs(Xreal)) ); pause()

subplot(3, 1, 3);

figure;

specgram(voltageFiltrado, 32, Fs)

subplot (2, 1, 1)

fplot (@sin, [-10, 10]);

subplot (2, 1, 2)

fplot (@cos, [-10, 10]);

input()

`

paulo-fernando-silva commented 3 years ago

I can try to take a look this weekend. Right now I believe this might be related to issue #24 In that issue I suggested to use

while true
  pause (1000/60);
end
print("Quitting...");

at the end of the code. That somehow seemed to help. Another option is setting the "autoTerminate": false, I can't remember exactly, but that might help. You'll have to press stop manually in that case.

paulo-fernando-silva commented 3 years ago

I tested that program on maxOS and it works without crashing with "autoTerminate": set to either false or true. But I guess that might be because of octave using aquaTerm on macOS. Did you test "autoTerminate": false ? Did it help?

VictorGerin commented 3 years ago

yes i did use autoTerminate = false, the plot didn't show.

1am commented 3 years ago

Hello. I'm experiencing the same on Ubuntu 20 and the only thing that helps is the while true loop at the end of the program. My script is very simple:

W = randn(1, 10000)
hist(W)

The plot only shows when the loop is there at the end.

If I set "autoTerminate": false the plot is not showing up (unless the loop at the end). If I have both "autoTerminate": false and the loop then on the other hand VSCode seems to disattach from octave-cli because stopping the program does not cause the plot to disappear after debug stops. What i need to do then is killall octave-cli to make the plot disappear.

So in short, in my case I need both "autoTerminate": false and the loop at the end.

Don't know if this helps but sharing my findings as I just started using Octave and your plugin, which I find great and very useful.

1am commented 3 years ago

Actually I've later found that the plots displayed with the while loop didn't have working cursors so I tried launching my octave script by octave command and the plot showed for just a moment and closed by itself. Then I've found this great StackOverflow thread https://stackoverflow.com/questions/52569584/octave-how-to-prevent-plot-window-from-closing-itself and what helped in my case is adding a waitfor call after the plot. I still get left over with bunch of abandoned octave-cli processes but it's better now.

Or even better - https://stackoverflow.com/a/62340602 which in an example below works great for me - just press any key to close the window and no octave-cli processes get left over

t = [0:0.01:0.98]
y1 = sin(pi * 2 * t)
plot(t, y1)
while (waitforbuttonpress ()==0) pause(1) end
paulo-fernando-silva commented 3 years ago

Hi Piotr, that's a great find. I like that solution so much I've decided to add it to the plugin readme. This seems to be a problem with octave scripts in general, but that solution also solves issue #24

In practice the "autoTerminate": false is not needed as the script will never exit due to the while loop. I've also tested setting a breakpoint on the last line where I added a disp('done...'). This will also prevent the script from exiting, so no loop is needed. You can still view the output as follows:

ScreenShot01

But checking for the keypress to exit works well for interactive UI elements such as sliders which was the case in issue #24. Additionally, I tested this using a virtualized windows 10 installation, and was able to get the code provided by @VictorGerin to work. I installed octave and set the path as follows:

ScreenShot00

Then I set "octave": "octave-gui" as "octave": "octave-cli"uses fltk and that's a bit wonky on windows. It seems to work properly. @VictorGerin let me know if this works for you.