问题
When I first use the plotting functions (for example, plot(1,1)
), Octave hangs for a few minutes. The second and subsequent calls for the same functions are performed quite quickly. The same behavior is repeated the next time you start Octave. I used Octave 4.2.1 with both qt graphics_toolkit and gnuplot graphics_toolkit. Operating system was Windows 7 and 10. I used standart Octave Installer.
How to solve this problem?
回答1:
This problem is quite common. See for example - Cannot use Octave 4.0.0 graphics toolkit functions or Plot doesn't work in Octave 4.0.0 But I did not find any solutions for this problem. So I made my own investigation.
I ran the well-known utility process-explorer when Octave was hanging up, and I saw that Octave opens all the files in the Windows fonts folder (c:\Windows\Fonts). The size of this folder on my computer is about 400 MByte! I search google and found, that Octave can use font's cache. There is special utility and script file for creating font's cache (see comment to bug). So solution for this problem is quite simple:
- Go to Octave folder (c:\Octave\Octave-4.2.1\ on my computer)
- Run script -
fc_update.bat
- Start Octave and check, that there is not any hang or freeze on first call of plotting functions.
There is a log of two sequential starts of this script:
c:\Octave\Octave-4.2.1>fc_update.bat
"Updating fc-cache (may take a while) ..."
C:/WINDOWS/fonts: caching, new cache contents: 1012 fonts, 0 dirs
C:/WINDOWS/fonts: failed to write cache
C:/Users/Sergey/.local/share/fonts: skipping, no such directory
C:/Users/Sergey/.fonts: skipping, no such directory
C:/Users/Sergey/AppData/Local/fontconfig/cache: cleaning cache directory
C:/Users/Sergey/.cache/fontconfig: not cleaning non-existent cache directory
C:/Users/Sergey/.fontconfig: cleaning cache directory
c:\Octave\Octave-4.2.1\bin\fc-cache.exe: failed
"Done."c:\Octave\Octave-4.2.1>fc_update.bat
"Updating fc-cache (may take a while) ..."
C:/WINDOWS/fonts: skipping, existing cache is valid: 1012 fonts, 0 dirs
C:/Users/Sergey/.local/share/fonts: skipping, no such directory
C:/Users/Sergey/.fonts: skipping, no such directory
C:/Users/Sergey/AppData/Local/fontconfig/cache: cleaning cache directory
C:/Users/Sergey/.cache/fontconfig: not cleaning non-existent cache directory
C:/Users/Sergey/.fontconfig: cleaning cache directory
c:\Octave\Octave-4.2.1\bin\fc-cache.exe: succeeded
"Done."
I think you need to run this script when installing Octave or adding new fonts to the system. I do not understand why this information is not contained in the Octave documentation in a clear and accessible way.
来源:https://stackoverflow.com/questions/48247690/octave-hangs-when-you-first-use-graphic-functions-plot-imagesc-etc