cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Browse apps to extend the software in the new JMP Marketplace
Choose Language Hide Translation Bar
dg1
dg1
Level III

Replacing Matrix Values

Hi! I am trying to input all my column data into a 8 by 12 matrix in order( filling in the columns first in a downwards manner). There are only 72 values in my column, so I want the remaining values that are not filled to be 0.  I am having a lot of problems trying to get the code below to work. I would appreciate any help!

dt = Open("Example.jmp");
Rows = nrows(dt); names= dt << Get Column Names (String); Table =[]; Table = J(8,12,0); For(i=1, i <= ncol(dt),i++, data = column(dt, names[i]) <<getValues; For(a=1, a <=12, a++, For(b =1, b <=8, b++, Table[a,b] = operation; // i get errors at this portion ); ); //unsure of the correct way to implement the code below operation= For (c =1, c= Rows, c++, DataInput[c] = Data[c]; ); ); Print(Table);
22 REPLIES 22
dg1
dg1
Level III

Re: Replacing Matrix Values

Thank you so much for your help. I appreciate it. I was able to save the file using your code, but currently the first row of the csv file is the first line of data, there is no column name. I would like to have the first cell to have the name of the column and right below that the 8 by 12 data.

Re: Replacing Matrix Values

I don't have your example so I had to use one of the JMP sample data tables. Replace those lines for the initial data table with your own.

 

Names Default to Here( 1 );

// use sample data to illustrate
dt = Open( "$SAMPLE_DATA/Fitness.jmp" );
// delete non-numeric data columns
dt << Delete Columns( { :Name, :Sex } );

// make empty container
table = Associative Array();

// get each data column and create (key, value) pair (key = col name, value = 8x12 matrix)
For( c = 1, c <= N Col( dt ), c++,
	data = Column( dt, c ) << Get As Matrix;
	If( N Row( data ) < 96,
		data |/= J( 96 - N Row( data ), 1, 0 );
	);
	table[Column( dt, c ) << Get Name] = Transpose( Shape( data, 12, 8 ) );
);

Close( dt, No Save );

dir = Get Default Directory();

content = table << Get Contents;
For( t = 1, t <= N Items( content ), t++,
	dt = As Table( content[t][2] );
	file path = dir || content[t][1] || ".CSV";
	dt << Save( file path );
	Close( dt, No Save );
	text = Load Text File( file path );
	eol = Contains( text, "\!n" );
	text = Munger( text, 1, eol - 1, content[t][1] );
	Save Text File( file path, text );
);
dg1
dg1
Level III

Re: Replacing Matrix Values

Thank you! this works perfectly