00001 package Algorithms;
00002 import java.util.*;
00003
00004
00005 public class ArrayHandler {
00006
00010 int[][] gegevens;
00011 public ArrayHandler(int[][] gegevens) {
00012 this.gegevens=gegevens;
00013 }
00014
00015 public int[][] getBeginElementen(int index){
00016 int[][] result=new int[index+1][2];
00017 for(int i =0;i!=result.length;i++){
00018 result[i][0]=gegevens[i][0];
00019 result[i][1]=gegevens[i][1];
00020 }
00021 return result;
00022 }
00023
00024
00025 public int[][] getEindElementen(int index){
00026 int[][] result=new int[gegevens.length-index][2];
00027 for(int i =index;i!=gegevens.length;i++){
00028 result[i-index][0]=gegevens[i][0];
00029 result[i-index][1]=gegevens[i][1];
00030 }
00031 return result;
00032 }
00033
00034 public static float mean(float[] rij){
00035 float sum=totaal(rij);
00036 return sum/(float)(rij.length);
00037 }
00038
00039
00040 public static float totaal(float[] rij){
00041 float sum=0;
00042 for(int i=0;i!=rij.length;i++){
00043 sum+=rij[i];
00044 }
00045
00046 return sum;
00047 }
00048
00049 public static float[] repmat(float[] a,int keer){
00050 float[] result=new float[a.length*keer];
00051 for(int i=1;i<=keer;i++){
00052 for(int k=0;k!=a.length;k++){
00053 result[(i-1)*a.length+k]=a[k];
00054 }
00055 }
00056 return result;
00057 }
00058
00059
00060 public static int getMaxPos(float[] rij){
00061 int pos=-1;
00062 float max=Float.NEGATIVE_INFINITY;
00063 for(int i=0;i!=rij.length;i++){
00064 if(rij[i]>max){
00065 pos=i;
00066 max=rij[i];
00067 }
00068
00069 }
00070 if(pos==-1){
00071 Debug.print("ERROR IN ARRAYHANDLER: getMaxPos ; pos:= "+pos);
00072 Debug.print("de rij ziet er als volgt uit:");
00073 printrij(rij);
00074 }
00075
00076 return pos;
00077 }
00078
00079 public static int getMaxPos(ArrayList<Double> rij) {
00080 int pos = -1;
00081 double max = Double.NEGATIVE_INFINITY;
00082 for (int i = 0; i != rij.size(); i++) {
00083 if (rij.get(i) > max) {
00084 pos = i;
00085 max = rij.get(i);
00086 }
00087 }
00088 if (pos == -1) {
00089 Debug.print("ERROR IN ARRAYHANDLER: getMaxPos ; pos:= "
00090 + pos);
00091 Debug.print("de rij ziet er als volgt uit:");
00092 }
00093 return pos;
00094 }
00095
00096 public static int getMaxPos(double[] rij){
00097 int pos=-1;
00098 double max=Float.NEGATIVE_INFINITY;
00099 for(int i=0;i!=rij.length;i++){
00100 if(rij[i]>max){
00101 pos=i;
00102 max=rij[i];
00103 }
00104
00105 }
00106 if(pos==-1){
00107 Debug.print("ERROR IN ARRAYHANDLER: getMaxPos ; pos:= "+pos);
00108 Debug.print("de rij ziet er als volgt uit:");
00109 printrij(rij);
00110 }
00111
00112 return pos;
00113 }
00114
00115
00116
00117 public static int getMinPos(float[] rij){
00118 int pos=-1;
00119 float min=Float.POSITIVE_INFINITY;
00120 for(int i=0;i!=rij.length;i++){
00121 if(rij[i]<min){
00122 pos=i;
00123 min=rij[i];
00124 }
00125
00126 }
00127 if(pos==-1){
00128 Debug.print("ERROR IN ARRAYHANDLER: getMinPos ; pos:= "+pos);
00129 Debug.print("de rij ziet er als volgt uit:");
00130 printrij(rij);
00131 }
00132
00133 return pos;
00134 }
00135
00136 public static int getMinPos(double[] rij){
00137 int pos=-1;
00138 double min=Float.POSITIVE_INFINITY;
00139 for(int i=0;i!=rij.length;i++){
00140 if(rij[i]<min){
00141 pos=i;
00142 min=rij[i];
00143 }
00144
00145 }
00146 if(pos==-1){
00147 Debug.print("ERROR IN ARRAYHANDLER: getMinPos ; pos:= "+pos);
00148 Debug.print("de rij ziet er als volgt uit:");
00149 printrij(rij);
00150 }
00151
00152 return pos;
00153 }
00154
00155
00156 public static int getMinPos(ArrayList<Double> rij){
00157 int pos=-1;
00158 double min=Double.POSITIVE_INFINITY;
00159 for(int i=0;i!=rij.size();i++){
00160 if(rij.get(i)<min){
00161 pos=i;
00162 min=rij.get(i);
00163 }
00164
00165 }
00166 if(pos==-1){
00167 Debug.print("ERROR IN ARRAYHANDLER: getMinPos ; pos:= "+pos);
00168 Debug.print("de rij ziet er als volgt uit:");
00169 }
00170
00171 return pos;
00172 }
00173
00174
00175 public static float[] getPartOfArray(float[][] rij,int kolom){
00176 float[] result=new float[rij.length];
00177 for(int i=0;i!=rij.length;i++){
00178 result[i]=rij[i][kolom];
00179 }
00180 return result;
00181 }
00182
00183 public static void printrij(float[] rij){
00184 Debug.print("begin printrij:[");
00185 for(int i=0;i!=rij.length;i++){
00186 Debug.print(rij[i]);
00187 }
00188 Debug.print("einde printrij]");
00189 }
00190
00191
00192 public static void printrij(int[][] rij){
00193 for(int i=0;i!=rij.length;i++){
00194 printrij_horizontaal(rij[i]);
00195 }
00196
00197 }
00198
00199 public static void printrij(int[] rij){
00200
00201 for(int i=0;i!=rij.length;i++){
00202 Debug.print(rij[i]);
00203 }
00204
00205 }
00206
00207
00208 public static void printrij(double[] rij){
00209 Debug.print("begin printrij:[");
00210 for(int i=0;i!=rij.length;i++){
00211 Debug.print(rij[i]);
00212 }
00213 Debug.print("einde printrij]");
00214 }
00215
00216 public static void printrij_horizontaal(int[] rij){
00217
00218 for(int i=0;i!=rij.length;i++){
00219 System.out.print(rij[i]+" ");
00220 }Debug.print("");
00221
00222 }
00223
00224 public static void printrij_horizontaal(float[] rij){
00225
00226 for(int i=0;i!=rij.length;i++){
00227 System.out.print(rij[i]+" ");
00228 }
00229
00230 }
00231
00232
00233 public static int[][] Flip(int[][] rij){
00234 int[][] temp=new int[rij.length][2];
00235
00236 for(int i=0;i!=rij.length;i++){
00237 temp[rij.length-i-1][0]=rij[i][0];
00238 temp[rij.length-i-1][1]=rij[i][1];
00239 }
00240
00241 return temp;
00242 }
00243
00244
00245 public static void main (String args[]){
00246 int[][] waarden=new int[5][2];
00247 waarden[0][0]=1;
00248 waarden[0][1]=2;
00249 waarden[4][0]=5;
00250 waarden[4][1]=6;
00251 int[][] reverse=ArrayHandler.Flip(waarden);
00252 for(int i=0;i!=waarden.length;i++){
00253 Debug.print("(" +waarden[i][0] +"," +waarden[i][1]+")");
00254 }
00255 Debug.print("--------------------");
00256 for(int i=0;i!=reverse.length;i++){
00257 Debug.print("(" +reverse[i][0] +"," +reverse[i][1]+")");
00258 }
00259
00260 }
00261
00262 }