Choose Language Hide Translation Bar
Highlighted
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.
Highlighted

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 );
);
Learn it once, use it forever!
Highlighted
dg1
dg1
Level III

Re: Replacing Matrix Values

Thank you! this works perfectly
Article Labels

    There are no labels assigned to this post.