如何填写2点之间数组列表?数组、列表

由网友(痴守过去)分享简介:我有这块code。为了解释:的用户输入initcores数据和TTIME的数据(fcores是一个结果)。 欲填在x数组值从0到TTIME和从在yinitcores到fcores并做散点图中,x VS年。 我有一个问题:如果我把的(双T = 0; T< = fcores; T = T + fcores / 10....

我有这块code。  为了解释:

的用户输入initcores数据和TTIME的数据(fcores是一个  结果)。

欲填在x数组值从0到TTIME和从在y  initcores到fcores并做散点图中,x VS年。

我有一个问题:

       

如果我把的(双T = 0; T< = fcores; T = T + fcores / 10.0){                            y.add(T);

         

它给了我一个情节,但它是错误的。

         

如果我把的(双T = initcores; T< = fcores; ......(这是      正确的,因为我们是从initcores开始)

         

它不会出现在情节什么。

  

我不能做某事就在这里?

求EXCEL 宏 在表2填写 表1里面的数据 应为需要文件较多.所以直接VLOOKUP比较慢 希望用宏编辑能快点 求帮忙 2个表都在当前文件夹里面

感谢您!

  .........
         双initcores = getInitcores();
         双fcores = getFcores();
         双TTIME =的getTime();

         ArrayList的<双> X =新的ArrayList<双>();
         ArrayList的<双> Y =新的ArrayList<双>();

         //填写的x,y值
          对于(双T = 0; T< = TTIME; T + = TTIME / 10.0){
                  x.add(T);
          }
          对于(双T = initcores; T< = fcores; T + = fcores / 10.0){
                  y.add(T);
          }

时间序列系列=新的时间序列(核数);
                 的for(int i = 0; I< x.size();我++){
                         对于(INT J = 0; J< y.size(); J ++){

                        series.add(I,J);
                         }
                 }
     ..........
 

--------------编辑-------------------------------- ------

如果我使用:

 双[]×= {0.0,TTIME}; //时间轴
双[] Y = {initcores,fcores}; //核心轴的数量

时间序列系列=新的时间序列(核数);
        的for(int i = 0; I< x.length;我++){
            series.add(X [I]中,值Y [i]);
        }
 

它给了我一个情节只有2 points.That。这就是为什么我试图填补了点之间(X轴:0 TTIME,为Y轴:initcores-fcores)。

解决方案

你有你的 -loops错误。请使用以下的人,你应该就可以了:

 的for(int i = 0; I< = 10;我++){
     x.add(TTIME / 10.0 * I);
 }

 的for(int i = 0; I< = 10;我++){
     y.add(ini​​tcores +((fcores  -  initcores)/ 10 * I));
 }
 

这些循环会给你11分,但你可以将它们调整到您的需要。

更新

您自然会从列表中使用正确的值。确保两个列表有相同的长度。

 的ArrayList<双> X =新的ArrayList<双>();
ArrayList的<双> Y =新的ArrayList<双>();

......以上code ...

时间序列系列=新的时间序列(核数);
的for(int i = 0; I< x.size();我++){
    series.add(x.get(i)中,y.get(ⅰ));
}
 

i have this piece of code. To explain:

The user inputs "initcores" data and "ttime" data (the "fcores" is a result).

I want to fill the x array with values from 0 to ttime and the y from initcores to fcores and do the scatter plot ,x vs y.

I have one problem :

If i put " for (double t=0;t<=fcores;t=t+fcores/10.0){ y.add(t); "

it gives me a plot but its wrong.

if i put " for (double t=initcores ;t<=fcores;..." (which is right because we are starting from initcores)

it doesn't appear anything in the plot.

Am i not doing sth right here?

Thank you!

 ......... 
         Double initcores= getInitcores(); 
         Double fcores= getFcores(); 
         Double ttime=getTime(); 

         ArrayList<Double> x =new ArrayList<Double>(); 
         ArrayList<Double> y =new ArrayList<Double>(); 

         //fill x,y values 
          for (double t=0;t<=ttime;t+=ttime/10.0){ 
                  x.add(t);
          } 
          for (double  t=initcores;t<=fcores;t+=fcores/10.0){ 
                  y.add(t); 
          } 

TimeSeries series = new TimeSeries("Number of cores"); 
                 for (int i=0;i<x.size();i++){ 
                         for (int j=0;j<y.size();j++){ 

                        series.add(i,j); 
                         } 
                 } 
     ..........

--------------EDIT --------------------------------------

If i use :

double [] x = {0.0,ttime};           //time axis
double [] y = {initcores,fcores};  //number of cores axis

TimeSeries series = new TimeSeries("Number of cores");
        for (int i=0;i<x.length;i++){
            series.add(x[i],y[i]);
        }

it gives me a plot with only 2 points.That's why i am trying to fill the points between them (for x axis :0-ttime ,for y axis:initcores-fcores).

解决方案

You got your for-loops wrong. Use the following ones and you should be fine:

 for (int i=0;i<=10;i++){ 
     x.add(ttime / 10.0 * i);
 } 

 for (int i=0;i<=10;i++){ 
     y.add(initcores + ((fcores - initcores) / 10 * i)); 
 } 

These loops will give you 11 points, but you can adjust them to your needs.

Update

You naturally have to use the correct values from the list. Make sure that both lists have same length.

ArrayList<Double> x = new ArrayList<Double>(); 
ArrayList<Double> y = new ArrayList<Double>(); 

... above code ...

TimeSeries series = new TimeSeries("Number of cores");
for (int i=0;i<x.size();i++){
    series.add(x.get(i),y.get(i));
}

阅读全文

相关推荐

最新文章