There is no way to delete columns here and there and in general end up with a valid dense matrix.
If you want a view on some of the columns of the matrix you can use slice. julia> x = reshape(1:100, (10,10)); julia> slice(x, :, 1:3:10) 10x4 SubArray{Int64,2,Array{Int64,2},Tuple{Colon,StepRange{Int64,Int64}},1}: 1 31 61 91 2 32 62 92 3 33 63 93 4 34 64 94 5 35 65 95 6 36 66 96 7 37 67 97 8 38 68 98 9 39 69 99 10 40 70 100 If you want a new "first order" matrix then I don't think you will get something better than x = x[:, 1:3:10] What's your use case? On Thursday, October 22, 2015 at 10:48:21 AM UTC+2, Glen O wrote: > > The reason why it's not working is that you're re-assigning x, rather than > editing it. By running "x=x[....]", you're creating a copy of x with the > appropriate column removed, and then assigning x to point to the copy, > rather than to the original array. > > If you wanted to edit an array's values, you'd do something like > "x[:]=x[end:-1:1]" to reverse them in-place - this creates a reversed copy, > and then copies the values from that reversed copy into the original array. > Unfortunately, for removing columns or values, it's not quite so simple, > because you have to deal with changing the size of the matrix. > > To get a feel for what is involved, have a look at this: > > https://github.com/JuliaLang/julia/blob/master/base/array.jl > > That file has the definitions of the functions that you're trying to > mimic. As you'll see, they end up using "ccall" functions, which are used > to call C and Fortran libraries. I believe these are necessary if you wish > to alter the dimensions of an array in-place. > > On Thursday, 22 October 2015 09:55:55 UTC+10, Thuener Silva wrote: >> >> I want to change a matrix inside a function. Example( just to illustrate): >> >> julia> x = ones(2,3) >> 2x3 Array{Float64,2}: >> 1.0 1.0 1.0 >> 1.0 1.0 1.0 >> >> julia> function deletecolumns(x,i) >> x = x[:,1:size(x,2) .!= i] >> end >> deletecolumns (generic function with 1 method) >> >> julia> deletecolumns(x,1) >> 2x2 Array{Float64,2}: >> 1.0 1.0 >> 1.0 1.0 >> >> >> >> julia> x >> 2x3 Array{Float64,2}: >> >> 1.0 1.0 1.0 >> >> 1.0 1.0 1.0 >> >> The best way is to do "x = deletecolumns(x,1)" ? I want to make something >> more like delete!(x,1). >> >> >> Thanks in advance, >> Thuener Silva >> >