Subscribe Bookmark RSS Feed

Matrix has too many columns

kardopaska

Community Trekker

Joined:

Feb 24, 2016

Why can't JNK handle more than 128 columns? oops i mean JMP.

My script:

PrintMatrix(Index(1, 129))

Log output:

Matrix has too many columns in access or evaluation of 'Print Matrix' , Bad Argument( Index( 1, 129 ) ), Print Matrix/*###*/(Index( 1, 129 ))

In the following script, error marked by /*###*/

Print Matrix/*###*/(Index( 1, 129 ))

I like the ability of the PrintMatrix function to format a matrix into a string so i can write it to a file.  My actual use case is a matrix with the same number of rows and columns -- just showing a simple example here.

Update:

Thanks for the good suggestions, but to expand on my use case:

I have a 1024x1024 pixel image kind of like this:

image_mat = Shape(Index(1, 1024^2), 1024, 1024);

and with this simple one liner, i have tabs in between each intensity value AND a linefeed character instead of a tab after the last value of each row:

printed_mat_for_save = PrintMatrix(image_mat, <<style( "other" ), <<line begin( "" ), <<line end( "" ), <<separate( "\!t" ));

​And then I can write everything i need, including some headers, in another one liner.

SaveTextFile(name_of_savefile, Concat(header_for_save, "\!n", printed_mat_for_save )

Perhaps there are some alternatives to looping through a million values to char it and add a tab except for the last col of a row which gets a linefeed?

4 REPLIES
Craige_Hales

Staff

Joined:

Mar 21, 2013

PrintMatrix is for pretty-printing.  Not sure why there is a limit on the width.  You can use char(matrix) if you can use a not-so-pretty string.

12086_pastedImage_0.png

Craige
ms

Super User

Joined:

Jun 23, 2011

I don't know why there is a limit for Print Matrix.

Try the Char() function instead.

Save Text File("my_matrix.txt", Char(Index(1, 128)));

ms

Super User

Joined:

Jun 23, 2011

Substitute() is quite efficient. Try something like this:

image_mat = Shape(Index(1, 1024^2), 1024, 1024);

printed_mat_for_save = Substitute(Char(image_mat), ", ", "", " ", "\!t");

Save Text File("my_matrix.txt", printed_mat_for_save);


kardopaska

Community Trekker

Joined:

Feb 24, 2016

MS. You were almost there.  Here is my final result to get the formatting I Needed using substitute.  Thanks for pointing me in the right direction, but substitute "feels" like slower than doing a for loop.  And the way I did it with for loop, i can specify the width and number of decimals. 

With substitute method:

numpixels = 1024;

image_mat = Shape(Index(1, numpixels^2), numpixels, numpixels);

string_mat_with_tabs = Substitute(Char(image_mat),

  ", \!r\!n\!t", "\!n",

  " ", "\!t",

  "\!r\!n[\!t", "",

  "]", ""

  );

Brute Force for loops:

numpixels = 1024;

image_mat = Shape(Index(1, numpixels^2), numpixels, numpixels);

char_maxwidth = 10;

char_num_decimals = 6;

string_mat_with_tabs = "";

for( iii = 1, iii <= nrows(image_mat), iii++,

  each_row = AsList(image_mat[iii, 1::numpixels])[1];

  string_row = "";

  for( jjj = 1, jjj < nitems(each_row), jjj++,

  ConcatTo(string_row, char(each_row[jjj], char_maxwidth, char_num_decimals), "\!t");

  );

  ConcatTo(string_row, char(each_row[jjj], char_maxwidth, char_num_decimals), "\!n"); // last col gets new line

  ConcatTo(string_mat_with_tabs, string_row); // add string_row to the main guy

);