# General Usage

**URL:** https://discourse.julialang.org/c/usage/6.md?page=294

[Latest](https://discourse.julialang.org/latest.md) · [Categories](https://discourse.julialang.org/categories.md) · [Tags](https://discourse.julialang.org/tags.md)

**Page:** 295

---

## [What is Julia's maxk(Matlab) that returns the indice of top K largest values?](https://discourse.julialang.org/t/what-is-julias-maxk-matlab-that-returns-the-indice-of-top-k-largest-values/14100)

<div class="topic-metadata">

**Author:** [@complexfilter](https://discourse.julialang.org/u/complexfilter)\
**Replies:** 20\
**Last updated:** [May 9, 2023, 4:19pm UTC](https://discourse.julialang.org/t/what-is-julias-maxk-matlab-that-returns-the-indice-of-top-k-largest-values/14100 "2023-05-09T16:19:51Z")

</div>

I am currently converting my Matlab code into Julia code. In an effort to converting the Matlab off-the-shelf function maxk, which returns the values and indices of the top K largest/smallest values, I found it difficult…

---

## [Saving to encrypted files?](https://discourse.julialang.org/t/saving-to-encrypted-files/98555)

<div class="topic-metadata">

**Author:** [@Thanh\_nhut\_nhat](https://discourse.julialang.org/u/Thanh_nhut_nhat)\
**Replies:** 0\
**Last updated:** [May 9, 2023, 12:32pm UTC](https://discourse.julialang.org/t/saving-to-encrypted-files/98555 "2023-05-09T12:32:51Z")

</div>

is it posible to save a variable to encrypted file with password, and get variable from the encrypted file.

---

## [How to Plot Slope Field with only 1 Solution Line with CairoMakie?](https://discourse.julialang.org/t/how-to-plot-slope-field-with-only-1-solution-line-with-cairomakie/98479)

<div class="topic-metadata">

**Author:** [@Freya\_the\_Goddess](https://discourse.julialang.org/u/Freya_the_Goddess)\
**Replies:** 1\
**Last updated:** [May 9, 2023, 1:09pm UTC](https://discourse.julialang.org/t/how-to-plot-slope-field-with-only-1-solution-line-with-cairomakie/98479 "2023-05-09T13:09:31Z")

</div>

Hi all, I was trying to plot a Slope Field with only 1 solution line like this: CairoMakie can do better, I have come out with this but I have problem that in this code I cannot delete the contour!(...) and it i…

---

## [Sum with generic implementation is slower than double sum](https://discourse.julialang.org/t/sum-with-generic-implementation-is-slower-than-double-sum/98512)

<div class="topic-metadata">

**Author:** [@PaterPen](https://discourse.julialang.org/u/PaterPen)\
**Replies:** 2\
**Last updated:** [May 9, 2023, 12:28pm UTC](https://discourse.julialang.org/t/sum-with-generic-implementation-is-slower-than-double-sum/98512 "2023-05-09T12:28:09Z")

</div>

Why is the latter implementation slower? These results surprise me especially given the fact that we have less allocations. using BenchmarkTools mat = randn(1000, 1000) @btime sum(sum(x -\> x \> 1, mat, dims=1)) # 135.16…

---

## [CalculusWithJulia ODEs Part Question](https://discourse.julialang.org/t/calculuswithjulia-odes-part-question/98540)

<div class="topic-metadata">

**Author:** [@Freya\_the\_Goddess](https://discourse.julialang.org/u/Freya_the_Goddess)\
**Replies:** 0\
**Last updated:** [May 9, 2023, 10:36am UTC](https://discourse.julialang.org/t/calculuswithjulia-odes-part-question/98540 "2023-05-09T10:36:45Z")

</div>

Hi all, I want to know why the code in CalculusWithJulia produce different solution for the same Initial Value problem: y' = 0.2y(16-y) y(0)=3 The plot is great anyway, since CairoMakie is a bit difficult to handle, …

---

## [Fixing invalidation - what would an expert do?](https://discourse.julialang.org/t/fixing-invalidation-what-would-an-expert-do/98484)

<div class="topic-metadata">

**Author:** [@svilupp](https://discourse.julialang.org/u/svilupp)\
**Replies:** 3\
**Last updated:** [May 9, 2023, 9:47am UTC](https://discourse.julialang.org/t/fixing-invalidation-what-would-an-expert-do/98484 "2023-05-09T09:47:30Z")

</div>

First of all, thank you for the awesome tooling around this. I appreciate there isn’t a straightforward answer to each case. I’ve re-read and re-watched a few times: the blog post on invalidations and the post Snoop…

---

## [Manual colorbar location with Makie](https://discourse.julialang.org/t/manual-colorbar-location-with-makie/98533)

<div class="topic-metadata">

**Author:** [@Gravlax](https://discourse.julialang.org/u/Gravlax)\
**Replies:** 1\
**Last updated:** [May 9, 2023, 9:06am UTC](https://discourse.julialang.org/t/manual-colorbar-location-with-makie/98533 "2023-05-09T09:06:51Z")

</div>

Dear all, I was wondering which is the best way to set the location of a colorbar (associated to a heatmap) with makie. I have tried the bbox argument without success. There is also the translate! function but it does …

---

## [Ambiguous method bug in ReverseDiff](https://discourse.julialang.org/t/ambiguous-method-bug-in-reversediff/98461)

<div class="topic-metadata">

**Author:** [@liao2877104858](https://discourse.julialang.org/u/liao2877104858)\
**Replies:** 6\
**Last updated:** [May 9, 2023, 8:58am UTC](https://discourse.julialang.org/t/ambiguous-method-bug-in-reversediff/98461 "2023-05-09T08:58:59Z")

</div>

This is my code function p2vec(p) w\_b = p\[1:nr\] .+ b0; w\_out = reshape(p\[nr + 1:end\], ns, nr); # w\_out = clamp.(w\_out, -2.5, 2.5); w\_in = clamp.(-w\_out, 0, 2.5); return w\_in, w\_b, w\_out end function…

---

## [Ignore compat entry for loading extension (for debugging)](https://discourse.julialang.org/t/ignore-compat-entry-for-loading-extension-for-debugging/98535)

<div class="topic-metadata">

**Author:** [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Replies:** 0\
**Last updated:** [May 9, 2023, 8:49am UTC](https://discourse.julialang.org/t/ignore-compat-entry-for-loading-extension-for-debugging/98535 "2023-05-09T08:49:32Z")

</div>

I am working on a project that uses package A, which provides an extension when B is loaded. B has a \[compat\] entry as a weak dependency in A. Debugging a problem requires that I use B#main. So it will not load the ext…

---

## [Using ThinkJulia](https://discourse.julialang.org/t/using-thinkjulia/98462)

<div class="topic-metadata">

**Author:** [@AGoh2019](https://discourse.julialang.org/u/AGoh2019)\
**Replies:** 4\
**Last updated:** [May 9, 2023, 8:44am UTC](https://discourse.julialang.org/t/using-thinkjulia/98462 "2023-05-09T08:44:42Z")

</div>

using ThinkJulia Info: Precompiling ThinkJulia \[a7fb756-c18b-4c7f-87da-faca9ac81629\] Info: Skipping recompilation since precompile(false). Importing ThinkJulia \[a7fb756-c18b-4c7f-87da-faca9ac81629\] ERROR: LocalError: …

---

## [Doctests don't appear in REPL help mode](https://discourse.julialang.org/t/doctests-dont-appear-in-repl-help-mode/98534)

<div class="topic-metadata">

**Author:** [@gdalle](https://discourse.julialang.org/u/gdalle)\
**Replies:** 5\
**Last updated:** [May 9, 2023, 8:01am UTC](https://discourse.julialang.org/t/doctests-dont-appear-in-repl-help-mode/98534 "2023-05-09T08:01:36Z")

</div>

Hi there! Does anyone know why doctests are not displayed in the REPL help mode? For instance this works julia\> """ foo(x) Compute the foo. # Example \`\`\`julia foo…

---

## [Is this a good way to tar.gz a list of files](https://discourse.julialang.org/t/is-this-a-good-way-to-tar-gz-a-list-of-files/98532)

<div class="topic-metadata">

**Author:** [@sparrowhawk](https://discourse.julialang.org/u/sparrowhawk)\
**Replies:** 0\
**Last updated:** [May 9, 2023, 7:09am UTC](https://discourse.julialang.org/t/is-this-a-good-way-to-tar-gz-a-list-of-files/98532 "2023-05-09T07:09:37Z")

</div>

Hi, I have some code which I don’t control the output of, which generates a whole bunch of files per unique index. We have a restriction on the number of files (inodes) on our filesystem, so it would be nice to make a ta…

---

## [Plotting a phase portrait for the nonlinear system](https://discourse.julialang.org/t/plotting-a-phase-portrait-for-the-nonlinear-system/98514)

<div class="topic-metadata">

**Author:** [@moxeeeem](https://discourse.julialang.org/u/moxeeeem)\
**Replies:** 3\
**Last updated:** [May 9, 2023, 7:05am UTC](https://discourse.julialang.org/t/plotting-a-phase-portrait-for-the-nonlinear-system/98514 "2023-05-09T07:05:31Z")

</div>

How can I plot a phase portrait for the nonlinear system in Julia? For example: u=Y v=X \* (1 - X\*\*2) + Y.

---

## [Embedding Julia code in C](https://discourse.julialang.org/t/embedding-julia-code-in-c/98507)

<div class="topic-metadata">

**Author:** [@mb96](https://discourse.julialang.org/u/mb96)\
**Replies:** 4\
**Last updated:** [May 9, 2023, 12:13am UTC](https://discourse.julialang.org/t/embedding-julia-code-in-c/98507 "2023-05-09T00:13:10Z")

</div>

Hi there, I am trying to compile a simple C program that calls a Julia base function. However, it is not compiling. The C code reads as “”" #include \<stdio.h\> #include \<julia.h\> int main(){ jl\_init(); int index\_ve…

---

## [HDF5 utilising only a fraction of available system resources](https://discourse.julialang.org/t/hdf5-utilising-only-a-fraction-of-available-system-resources/98481)

<div class="topic-metadata">

**Author:** [@silkskier](https://discourse.julialang.org/u/silkskier)\
**Replies:** 5\
**Last updated:** [May 8, 2023, 10:41pm UTC](https://discourse.julialang.org/t/hdf5-utilising-only-a-fraction-of-available-system-resources/98481 "2023-05-08T22:41:37Z")

</div>

I’ve recently written a simple script converting the OCVS (OGLE Collection of Variable Stars) database (which is basically a single text file containing a list of attributes of every star in the collection) and a large a…

---

## [Create array of empty (separate) vectors](https://discourse.julialang.org/t/create-array-of-empty-separate-vectors/98493)

<div class="topic-metadata">

**Author:** [@Torkel](https://discourse.julialang.org/u/Torkel)\
**Replies:** 5\
**Last updated:** [May 8, 2023, 10:27pm UTC](https://discourse.julialang.org/t/create-array-of-empty-separate-vectors/98493 "2023-05-08T22:27:56Z")

</div>

I want to initialise a number of (in this case empty) vectors. However, if I do e.g. x = fill(\[\],4) push!(x\[1\],3) x\[2\] I get \[3\]. Basically, I put in the same vector 4 times, so now when I modify one, I modify all. Wh…

---

## [Randomized SVD](https://discourse.julialang.org/t/randomized-svd/98488)

<div class="topic-metadata">

**Author:** [@Desmond](https://discourse.julialang.org/u/Desmond)\
**Replies:** 6\
**Last updated:** [May 8, 2023, 10:25pm UTC](https://discourse.julialang.org/t/randomized-svd/98488 "2023-05-08T22:25:37Z")

</div>

I am implement the randomized SVD without power iteration and I am just getting a black and white dots as the output of the SVD. I can’t seem to spot the problem. Here is the code function rsvd(X,k) (m,n)=size(X) …

---

## [Current directory @\_\_DIR\_\_](https://discourse.julialang.org/t/current-directory-dir/98502)

<div class="topic-metadata">

**Author:** [@sirion34](https://discourse.julialang.org/u/sirion34)\
**Replies:** 1\
**Last updated:** [May 8, 2023, 7:34pm UTC](https://discourse.julialang.org/t/current-directory-dir/98502 "2023-05-08T19:34:51Z")

</div>

How do i make julia think she is in a specific directory? exe = """ begin @info @\_\_DIR\_\_ @info pwd() end """ cmd = Base.julia\_cmd() cmd = \`$cmd -e $exe\` procs = open(cmd) I need to be able to …

---

## [Avoiding computing inverse of matrix, don't think it's possible in my case](https://discourse.julialang.org/t/avoiding-computing-inverse-of-matrix-dont-think-its-possible-in-my-case/98478)

<div class="topic-metadata">

**Author:** [@p\_f](https://discourse.julialang.org/u/p_f)\
**Replies:** 4\
**Last updated:** [May 8, 2023, 4:03pm UTC](https://discourse.julialang.org/t/avoiding-computing-inverse-of-matrix-dont-think-its-possible-in-my-case/98478 "2023-05-08T16:03:53Z")

</div>

I have a system of (6+3N) equations given by: A\*inv(B)\*C\*dX = K which I then solve using dX = (A\*inv(B)\*C) \\ K A\*inv(B)\*C form a square (6+3N) matrix but the submatrices have sizes: A: (6+3N) x (6N) B: (6N) x (6N) …

---

## [How to find the local extrema of the solutions when solving a differential equation？](https://discourse.julialang.org/t/how-to-find-the-local-extrema-of-the-solutions-when-solving-a-differential-equation/94628)

<div class="topic-metadata">

**Author:** [@YiboXia](https://discourse.julialang.org/u/YiboXia)\
**Replies:** 15\
**Last updated:** [May 8, 2023, 3:48pm UTC](https://discourse.julialang.org/t/how-to-find-the-local-extrema-of-the-solutions-when-solving-a-differential-equation/94628 "2023-05-08T15:48:40Z")

</div>

Hello guys, I got a problem when I want to calculate the local extrema in an ODE. I did the following steps: define the ODE problem; define a integrator integ; take 2000 successful step ahead to insure the trajectory …

---

## [Tracking the cause of allocation in the presence of a generated function](https://discourse.julialang.org/t/tracking-the-cause-of-allocation-in-the-presence-of-a-generated-function/98215)

<div class="topic-metadata">

**Author:** [@mateuszbaran](https://discourse.julialang.org/u/mateuszbaran)\
**Replies:** 1\
**Last updated:** [May 8, 2023, 2:04pm UTC](https://discourse.julialang.org/t/tracking-the-cause-of-allocation-in-the-presence-of-a-generated-function/98215 "2023-05-08T14:04:42Z")

</div>

I have some trouble tracking why the following code allocates: julia\> using HybridArrays, StaticArrays \[ Info: Precompiling HybridArrays \[1baab800-613f-4b0a-84e4-9cd3431bfbb9\] julia\> using BenchmarkTools julia\> H = Hy…

---

## [Very slow time to first plot, 2022](https://discourse.julialang.org/t/very-slow-time-to-first-plot-2022/88968)

<div class="topic-metadata">

**Author:** [@rongcuid](https://discourse.julialang.org/u/rongcuid)\
**Replies:** 72\
**Last updated:** [May 8, 2023, 10:08am UTC](https://discourse.julialang.org/t/very-slow-time-to-first-plot-2022/88968 "2023-05-08T10:08:17Z")

</div>

Obviously, we all know this question has been asked numerous times. I am using latest Julia 1.8, and in my current research I am using Julia Makie/AlgebraOfGraphics for most of the analytics and plotting, and I am encou…

---

## [Performance of function with pre-allocated outputs](https://discourse.julialang.org/t/performance-of-function-with-pre-allocated-outputs/98457)

<div class="topic-metadata">

**Author:** [@jekyllstein](https://discourse.julialang.org/u/jekyllstein)\
**Replies:** 3\
**Last updated:** [May 8, 2023, 8:19am UTC](https://discourse.julialang.org/t/performance-of-function-with-pre-allocated-outputs/98457 "2023-05-08T08:19:37Z")

</div>

Consider the following mutating function that mutates a vector input: function f\_test!(xout::Vector{T}, a::T, b::T) where T \<: Real xout .= a .\* b view(xout, 1:max(1, lastindex(xout)-5)) .-= b return xout end I time…

---

## [IOError undocumented](https://discourse.julialang.org/t/ioerror-undocumented/98156)

<div class="topic-metadata">

**Author:** [@screw\_dog](https://discourse.julialang.org/u/screw_dog)\
**Replies:** 1\
**Last updated:** [May 8, 2023, 7:34am UTC](https://discourse.julialang.org/t/ioerror-undocumented/98156 "2023-05-08T07:34:58Z")

</div>

The Base.Filesystem module tends to throw IOError exceptions but these aren’t documented at all. I want to be able to catch these and determine the exact problem (ie incorrect permissions, file doesn’t exist, etc) but th…

---

## [Decomposing struct in function argument](https://discourse.julialang.org/t/decomposing-struct-in-function-argument/97468)

<div class="topic-metadata">

**Author:** [@Lincoln\_Hannah](https://discourse.julialang.org/u/Lincoln_Hannah)\
**Replies:** 4\
**Last updated:** [May 8, 2023, 12:06am UTC](https://discourse.julialang.org/t/decomposing-struct-in-function-argument/97468 "2023-05-08T00:06:08Z")

</div>

is it possible to to something like this? struct X a b end f((a,b)::X) = a+b

---

## [Reference versus copy](https://discourse.julialang.org/t/reference-versus-copy/98447)

<div class="topic-metadata">

**Author:** [@erlebach](https://discourse.julialang.org/u/erlebach)\
**Replies:** 5\
**Last updated:** [May 7, 2023, 11:47pm UTC](https://discourse.julialang.org/t/reference-versus-copy/98447 "2023-05-07T23:47:41Z")

</div>

I create a simple MWE to demonstrate some kind of reference problem which is leading to unwanted behavior when creating matrices with function elements. Here is the code: function test() zfcts = Any\[t -\> 0., t -\> 0.…

---

## [Strange performance issue on 1.9.0-rc3](https://discourse.julialang.org/t/strange-performance-issue-on-1-9-0-rc3/98427)

<div class="topic-metadata">

**Author:** [@MilesCranmer](https://discourse.julialang.org/u/MilesCranmer)\
**Replies:** 9\
**Last updated:** [May 7, 2023, 10:44pm UTC](https://discourse.julialang.org/t/strange-performance-issue-on-1-9-0-rc3/98427 "2023-05-07T22:44:34Z")

</div>

I’m seeing a weird performance issue related to the presence of an if-statement in my function, regardless of the if-statement being triggered or not. I can only reproduce this in 1.9.0, not earlier Julia versions. I ha…

---

## [Method Error in simple LoopVectorization call](https://discourse.julialang.org/t/method-error-in-simple-loopvectorization-call/98444)

<div class="topic-metadata">

**Author:** [@Alec\_Loudenback](https://discourse.julialang.org/u/Alec_Loudenback)\
**Replies:** 2\
**Last updated:** [May 7, 2023, 7:29pm UTC](https://discourse.julialang.org/t/method-error-in-simple-loopvectorization-call/98444 "2023-05-07T19:29:43Z")

</div>

With this simple example, I get an error where I do not expect it when looping over a Vector{Int} with length 2. using LoopVectorization function f(v) x = zero(eltype(v)) @turbo for i ∈ eachindex(v) amt …

---

## [Private fields with \`fieldnames\` and \`propertynames\`](https://discourse.julialang.org/t/private-fields-with-fieldnames-and-propertynames/98442)

<div class="topic-metadata">

**Author:** [@sirion34](https://discourse.julialang.org/u/sirion34)\
**Replies:** 5\
**Last updated:** [May 7, 2023, 7:20pm UTC](https://discourse.julialang.org/t/private-fields-with-fieldnames-and-propertynames/98442 "2023-05-07T19:20:40Z")

</div>

everywhere write that with the help of propertynames I can set public and private fields, but how legal is it to do this with fieldnames? Struct the structure stores its fields in Struct\*.name.names and I can overload fi…

---

## [Execute a matrix of functions](https://discourse.julialang.org/t/execute-a-matrix-of-functions/98440)

<div class="topic-metadata">

**Author:** [@erlebach](https://discourse.julialang.org/u/erlebach)\
**Replies:** 15\
**Last updated:** [May 7, 2023, 6:59pm UTC](https://discourse.julialang.org/t/execute-a-matrix-of-functions/98440 "2023-05-07T18:59:45Z")

</div>

I have defined a 3x3 matrix of functions (all cos(t)) as follows: vij = SizedMatrix{3,3}(\[t-\>cos(t) for i in 1:3 for j in 1:3\]) I’d like to execute the matrix for a particular value of t, say t=2.: values = \[vij\[i,j\](…

[Previous page](https://discourse.julialang.org/c/usage/6.md?page=293)

[Next page](https://discourse.julialang.org/c/usage/6.md?page=295)
