specified cells from csv to matrix

35 views
Skip to first unread message

Suhad Faisal

unread,
Jul 3, 2014, 1:39:26 PM7/3/14
to gama-p...@googlegroups.com
Hello 

I have a problem with reading a specific fields from csv file as in the following model : where I need to deal with just the pos_x, pos_y fields to assign them as a matrix cell but gama read them differently 

any advice to adjust it 

model Matrix
/* file my_csv_file <- csv_file("../includes/iris.csv",",");
init {
matrix data <- matrix(my_csv_file);
loop i from: 1 to: data.rows -1{
loop j from: 0 to: data.columns -1{
write "data rows:"+ i +" colums:" + j + " = " + data[j,i];
 */
 
global { 
file Peoplefile4<-file('../includes/41821.csv');
int i;
int j;
 
{  matrix data<- matrix(Peoplefile4);
    loop i from: 1 to:  data.rows
     {
       loop j from: 4 to: 5
        {  
          write "data rows:"+ i +" colums:" + j + " = " + data[j,i];
          
        create People from: data header:true  
        with:[i::int(read('pos_x')),j::int(read('pos_y'))];
        
        location<-data[i, j];             
       }
       
       }
       }   
  entities { species People
  {
  int i; 
  int j;
  aspect basepeople {draw circle(0.5) color:rgb("yellow") at:location;}
  }
}
experiment Citymatrix type: gui {
output { display disp 
{    
 
 species People   aspect: basepeople;
}    }
}    }

thanks in advance 

suhad


Patrick Taillandier

unread,
Jul 5, 2014, 5:19:51 AM7/5/14
to gama-p...@googlegroups.com
Hi,

Just a warning concerning CSV file: you should use US formatting for number: "3.5" and not "3,5" (french formatting).
Concerning the separator, you use the good one (by default, GAMA uses "," as separator) :
file Peoplefile4<-file('../includes/41821.csv', my_separator);

Cheers,

Patrick


--
You received this message because you are subscribed to the Google Groups "GAMA" group.
To unsubscribe from this group and stop receiving emails from it, send an email to gama-platfor...@googlegroups.com.
To post to this group, send email to gama-p...@googlegroups.com.
Visit this group at http://groups.google.com/group/gama-platform.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages