2016-05-06 5 views
1

基本的に私は9つの異なるステートメントを評価しようとしており、それらの絶対値の最小値を見つけようとしています。次に、ステートメントのNON絶対値をセルに戻したいと思います。これは、複数のセルにまたがって展開されることを意味します。したがって、私の入力は=getCorrectedRotation(E5:5,F5:5,F14:14)このGoogleスクリプトで何が問題になっていますか?

です。#REFエラーが発生しました。何か案は?

function getCorrectedRotation(previous, current, step) { 
    var r=0,s=0,t=0,u=0,v=0,w=0,x=0,y=0,z=0 
    var points = step.length; 
    var output = []; 
    var i; 
    for (i = 0; i < points; i++) { 
    r = ((current[i]-previous[i])/step[i]) 
    s = (((current[i]+360)-previous[i])/step[i]) 
    t = (((current[i]-360)-previous[i])/step[i]) 
    u = (((current[i]+360)-(previous[i]+360))/step[i]) 
    v = (((current[i]+360)-(previous[i]-360))/step[i]) 
    w = (((current[i]-360)-(previous[i]+360))/step[i]) 
    x = (((current[i]-360)-(previous[i]-360))/step[i]) 
    y = ((current[i]-(previous[i]+360))/step[i]) 
    z = ((current[i]-(previous[i]-360))/step[i]) 
    switch (Math.min(Math.abs(r),Math.abs(s),Math.abs(t),Math.abs(u),Math.abs(v),Math.abs(w),Math.abs(x),Math.abs(y),Math.abs(z))) { 
    case Math.abs(r): 
     output.push(r); 
     break; 
    case Math.abs(s): 
     output.push(s); 
     break; 
    case Math.abs(t): 
     output.push(t); 
     break; 
    case Math.abs(u): 
     output.push(u); 
     break; 
    case Math.abs(v): 
     output.push(v); 
     break; 
    case Math.abs(w): 
     output.push(w); 
     break; 
    case Math.abs(x): 
     output.push(x); 
     break; 
    case Math.abs(y): 
     output.push(y); 
     break; 
    case Math.abs(z): 
     output.push(z); 
     break; 
    } 
} 
    return output; 
} 
+0

ここにスプレッドシートbtwへのリンクがあります。私はF12で関数を呼び出そうとしています。 https://docs.google.com/spreadsheets/d/19zfc7XAgDbg6hVIybsOldKNsX5pt0DIQPetk7I-0QaA/edit?usp=sharing – TRS

答えて

0

参考エラーのようですが、おそらくJavaのArrayIndexOutOfBoundsエラーのJavaScriptに相当します。私は

var points = step.length-1; 

var points = step.length; 

を変更しようとすると、ほとんどの「長さ」のパラメータは、要素数(すなわち、最大の参照1)されているとしてそれは、あなたの問題を修正した場合に参照してくださいね。つまり、配列の外側にあるため存在しない「最後の点」を参照しているだけです。

+0

Nope。何も変更していない:(私はそれを追加する前にこの問題があった – TRS

関連する問題