Вопрос

I am using Scilab to average an 100x100x100 matrix in 2x2x2 cubes.How can I change this script so that it averages it in 9x9x9 cubes?I know 100^3 doesn't divide evenly into 9x9x9 cubes.I just want to average it until it can no longer be evenly diveded.

a=1 b=1 c=1 numbers = rand(100,100,100) while c <=99, if a>99 then a=1 b=b+2 c=1; end if b>99 then a=1 b=1 c=c+2; end average=(numbers(a,b,c)+numbers(a+1,b,c)+numbers(a,b+1,c)+numbers(a+1,b+1,c) +numbers(a,b,c+1)+numbers(a+1,b,c+1)+numbers (a,b+1,c+1)+numbers(a+1,b+1,c+1))/8
a=(a+2); end

Это было полезно?

Решение

You need to use the matrix function that is built into scilab. Simply use this at each iteration with cubes of the desired size.

Другие советы

Not exactly sure what you want but:

mean(numbers(1:9, 1:9, 1:9))

is probably what you need.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top