I have a code (simplified as in the below code) put in a file. When I run it, an output of the “W” matrix is automatically displayed in the REPL after the execution of the code, although all the assignment are ended by “;”. I dont want this display to happen. Any solution for that?
using SparseArrays
Base.@kwdef mutable struct RLCs
SS::Vector{Float64} = [0,0,0]
end
RLC = RLCs[];
for i in 1:3
push!(RLC, RLCs([1,2,3]));
end
function KK(RLC::Vector{RLCs})
dt=5;
W= spzeros(size(RLC,2),size(RLC,2));
for i in eachindex(RLC)
W[i,i] = RLC[i].SS[1];
end
W;
end
RR = KK(RLC);
You don’t need to place ;'s on inner lines, only on the REPL line if you want to suppress output.
Your example doesn’t work for me though.
I suspect you may be calling some previously compiled function that had a display or something similar.
Have you tried your code in a new session?
julia> using SparseArrays
julia> Base.@kwdef mutable struct RLCs
SS::Vector{Float64} = [0,0,0]
end
RLCs
julia> RLC = RLCs[];
julia> for i in 1:3
push!(RLC, RLCs([1,2,3]))
end
julia> function KK(RLC::Vector{RLCs})
dt = 5
W = spzeros(size(RLC,2),size(RLC,2))
for i in eachindex(RLC)
W[i,i] = RLC[i].SS[1]
end
W
end
KK (generic function with 1 method)
julia> RR = KK(RLC);
ERROR: BoundsError: attempt to access 1×1 SparseMatrixCSC{Float64, Int64} at index [2, 2]
Stacktrace:
[1] _setindex_scalar!(A::SparseMatrixCSC{Float64, Int64}, _v::Float64, _i::Int64, _j::Int64)
@ SparseArrays /Users/julia/buildbot/worker/package_macos64/build/usr/share/julia/stdlib/v1.6/SparseArrays/src/sparsematrix.jl:2581
[2] setindex!
@ /Users/julia/buildbot/worker/package_macos64/build/usr/share/julia/stdlib/v1.6/SparseArrays/src/sparsematrix.jl:2574 [inlined]
[3] KK(RLC::Vector{RLCs})
@ Main ./REPL[12]:5
[4] top-level scope
@ REPL[13]:1
I get no output. Are you running this in an IDE?
I ran this directly in the julia 1.6.2 terminal
julia> using SparseArrays
julia> Base.@kwdef mutable struct RLCs
SS::Vector{Float64} = [0,0,0]
end
RLCs
julia> RLC = RLCs[];
julia> for i in 1:3
push!(RLC, RLCs([1,2,3]))
end
julia> function KK(RLC::Vector{RLCs})
dt=5;
W= spzeros(size(RLC,1),size(RLC,1));
for i in eachindex(RLC)
W[i,i] = RLC[i].SS[1];
end
W;
end
KK (generic function with 1 method)
julia> RR = KK(RLC);
julia>