1

I have a table where I imported data using javaaddpath. I would like to limit the significant figures of this java database in Matlab.

I use javaaddpath to add the string I would like to work in and from there I select a database. Once in the database I fill a listbox with messages from the java database. From there I generate a template and check off the ones I would like to work with and hit a plot button. This populates a table with data (again, from the database in java). I would like to know how to limit the significant figures of the numbers that fill up that table.

format short

and

fprintf

aren't really relevant to me here because I'm trying to put the output into a table, which stores as a cell array. I'm currently working on trying the function

vpa(A,d)

but it doesn't accept a cell array or a matrix. I am willing to populate the table as normal, extract the data, format it, and then repopulate the table, I'm just unsure how to do so.

Any help or websites to point me to would be very much appreciated. I also posted this query on the Mathworks help forum (here), but haven't had any luck.

Robert Seifert
  • 25,078
  • 11
  • 68
  • 113
Nicole Ouellette
  • 97
  • 2
  • 2
  • 11

1 Answers1

1

You can set the ColumnFormat property of the uitable to be any string that the format command accepts. For example, if your table has one column you can set the property to {'short g'} (it has to be a cell array, one value per column).

Note that although the format command accepts shortg, in some releases of MATLAB the ColumnFormat property only accepts short g with a space (I think this is a bug).

If you need a number of significant figure that is not provided by one of the options to the format command, the best solution I've found is to set all the column formats to char, and convert numerical contents to strings myself using the more flexible capabilities of sprintf.

Sam Roberts
  • 23,951
  • 1
  • 40
  • 64
  • I set the ColumnFormat property to {'bank'} based for each of the columns that needed it and no errors were returned... however, the table is still displaying 9+ digits after the decimal. Any thoughts on why this would be happening? – Nicole Ouellette Jul 10 '13 at 18:17
  • I don't. Try this: `u = uitable; set(u,'Data',rand(3,3));`. You should get nine cells, all with the default 4 d.p. `set(u,'ColumnFormat',{'bank','bank','bank'})`. All nine cells should now display at 2 d.p. Is that not what you get? – Sam Roberts Jul 11 '13 at 16:49
  • Yes, it is. I figured out that if I declare the data as a matrix within the code first, it recognizes the ColumnFormat property I set. Thank you so much for your help! – Nicole Ouellette Jul 12 '13 at 13:32