Thx Stefan (Dziękuję Stefan ;))
it is working :
a=rand(100)
b=zeros(100)
[b[i:min(i+9,end)]=mean(a[i:min(i+9,end)]) for i=1:10:length(a) ]
Paul
W dniu wtorek, 10 lutego 2015 14:59:08 UTC+1 użytkownik Stefan Karpinski
napisał:
>
> There's always going to be a loop since that's what the computer is doing.
> Either you wrote it or someone wrote it for you. In this case you can use a
> comprehension:
>
> [ mean(b[i:min(i+9,end)]) for i=1:10:length(b) ]
>
>
> On Tue, Feb 10, 2015 at 5:48 AM, paul analyst <[email protected]
> <javascript:>> wrote:
>
>> ok, it is jumping average :)
>> Nice way, thx, but unfortunatly lenght of my vecotrs are random, 100 it
>> was only like sample.
>> reshape of vector length on 256845 is imposible:)
>> Paul
>>
>>
>> W dniu wtorek, 10 lutego 2015 11:18:55 UTC+1 użytkownik Gunnar Farnebäck
>> napisał:
>>
>>> If speed is what's important you almost certainly want some kind of loop.
>>>
>>> If it's more important not to have a loop you can satisfy your
>>> specification with
>>>
>>> b = reshape(repmat(mean(reshape(a,10,10),1),10),100)
>>>
>>> although that's not what I would call a moving average.
>>>
>>> Den tisdag 10 februari 2015 kl. 10:00:36 UTC+1 skrev paul analyst:
>>>>
>>>> How to quickly count the moving average with one vector and save the other
>>>> vector?
>>>> I have vec a and need to fill vec b moving average of a, in this same
>>>> range.
>>>> Is posible to do it whitout while ?
>>>>
>>>> julia> a=rand(100);
>>>> julia> b=zeros(100);
>>>>
>>>> julia> b[1:10]=mean(a[1:10])
>>>> 0.6312220153427996
>>>>
>>>> julia> b[11:20]=mean(a[11:20])
>>>> 0.6356771620528772
>>>>
>>>> julia> b
>>>> 100-element Array{Float64,1}:
>>>> 0.631222
>>>> 0.631222
>>>> 0.631222
>>>> 0.631222
>>>> 0.631222
>>>> 0.631222
>>>> 0.631222
>>>> 0.631222
>>>> 0.631222
>>>> 0.631222
>>>> 0.635677
>>>> 0.635677
>>>> 0.635677
>>>> 0.635677
>>>> 0.635677
>>>> 0.635677
>>>> 0.635677
>>>> 0.635677
>>>> 0.635677
>>>> ?
>>>> 0.0
>>>>
>>>>
>>>> Paul
>>>> 0.0
>>>>
>>>
>