Quantcast
Channel: First steps - JuliaLang
Viewing all articles
Browse latest Browse all 2795

How to apply a function only to the second column of a matrix

$
0
0

How to apply a function only to the second column of a matrix

The only way I know of is this. Is there an easier way to apply the sin function to only the second column of a matrix?

julia> m = [1. 2. 3.; 4. 5. 6.; 7. 8. 9. ]
3×3 Array{Float64,2}:
 1.0  2.0  3.0
 4.0  5.0  6.0
 7.0  8.0  9.0

julia> for k = 1:size(m)[1]
           m[k,2] = sin(m[k,2])
       end

julia> m
3×3 Array{Float64,2}:
 1.0   0.909297  3.0
 4.0  -0.958924  6.0
 7.0   0.989358  9.0

3 posts - 2 participants

Read full topic


Viewing all articles
Browse latest Browse all 2795

Trending Articles