MATLAB UITABLE AND FORMAT OPTIONS - matlab

I have followed many posts about format of numbers in Matlab. Now I have set up Matlab uitable in such a way that one can fill the table cell by cell. I want the first column to maintain numbers up to say 12 digits, so I set the format to longG. Matlab uitable is refusing to accept my format and the frustrating part is, in the command window all digits are shown even up to 15 digits with format longG option. This is the sample;
colNam={'W','X','Y','Z'};
t=uitable('ColumnName',colNam,'Data',zeros(4),'ColumnEditable',...
[true true true true],'ColumnWidth',{150,'auto'},...
'ColumnFormat',{'numeric'});
set(t,'ColumnFormat',{'longG'});
I know of sprintf and fprintf as has been explained elsewhere. But please what we are refusing to realize is that, these change the class of the number from double to char. What if you want to set up the table so that it increases by 1 dynamically (credits to thewaywewalk)? We can't add double to char for this purpose. Please this is frustrating. Any suggestions? Thank you.

There is no such ColumnFormat property called "longG", where dis you see that ?
You have the possibility of manipulating the Java part of the Uitable in order to really display numeric values... but I think the best (and easiest) way is to use char.
If you want to increase the values, just convert it first to numeric, increase, then convert it back.

Based on John's suggestion, I put up this code and I could set the table to accept any number of digits.
f=figure;
dat=[101100220001;101100220002;101100220003;101100220004;101100220005];
colNam={'W'};
t=uitable('ColumnName',colNam,'Data',dat,'ColumnEditable',...
[true],'ColumnWidth',{150},'pos',[5 250 200 120]);
newdat=get(t,'Data');
newdat=strtrim(cellstr(num2str(newdat))); %Convert data to cell array of strings
tt=uitable('ColumnName',colNam,'Data',newdat,'pos',[300 250 200 120]);

Related

LibreOffice Calc -- countif based on string length

I'd like to setup a countif function that counts the cells in a range based on the cell string length.
I've tried inserting the formula as an argument to the countif function, but I can't get it to work.
I wanted to compare the length for each cell in the range with a specific lenght defined somewhere else, but I don't know how to reference back the cell in the range.
One of my failed attempts was =COUNTIF($'Delovni list1'.$D$3:$D$102;">2")
given that the cells in the range are formatted as text. But the above doesn't even work if there are numbers in the cells.
My use case is this: I need to count the cells with 1 specific letter and cells which have many characters.
Thank you.
seba
I found this to work:
=COUNTIF($'Delovni list1'.$D$3:$D$102;"[:alnum:]..*")
regards,
seba

printmat function: Decimal and percentage

I am very new to MATLAB. I am sorry if my question is basic. I am using "printmat" function to show some matrices in the command console. For example, printmat(A) and printmat(B), where A = 2.79 and B = 0.45e-7 is a scalar (for the sake of simplicity).
How do I increase the precision arbitrarily to seven decimals? For example: my output looks like 2.7943234 and B = 0.00000004563432.
How do I add a currency (say dollar) figure to the output of printmat?
How do I add a percentage figure (%) to the output of printmat?
Note: The reason I use printmat is that I can name my rows and columns. If you know a better function that can do all above, I would be glad to know.
Regards Mariam. From what I understand, you would like to display the numbers and show their full precision. I am also newbie, If I may contribute, you could convert the number data to string data (for display purposes) by using the sprintf function.
I am using the variable A=2.7943234 as example. This value will not display the full precision, instead it will display 2.7943. To show all the decimal tails, you could first convert this to string by
a = sprintf('%0.8f',A);
It will set the value a to a string '2.79432340'. The %0.8f means you want it to display 8 decimal tails. For this example,%0.7f is sufficient of course.
Another example: A=0.00000004563432, use %0.14f.
A=0.00000004563432;
a=sprintf('%0.14f $ or %%',A);
the output should be : '0.00000004563432 $ or %'.
You could analyze further in https://www.mathworks.com/help/matlab/ref/sprintf.html
You could try this first. If this does not help to reach your objective, I appreciate some inputs. Thanks.
The printmat function is very obsolete now. I think table objects are its intended successor (and functions such as array2table to convert a matrix to a table of data). Tables allow you to add row and column names and format the columns in different ways. I don't think there's a way to add $ or % to each number, but you can specify the units of each column.
In general, you can also format the display precision using format. Something like this may be what you want:
format long

Excel, Unable to change the number format

I was wondering if somebody could help me with this one. It’s probably so simple, but its got me at a loss.
I have a Excel spreadsheet looking like this
Basically it’s a simple if statement if A1 = 10 then B1 will display 600, if not it will display a 0. It works ……but I can not format the number in B1, I right click Format cell, number, and select currency with 2 decimal places. No change . Colour, alignment, Boarder and fill works, its just the number type will not. B1 will feed other cells to workout a formulas. I need it in a currency format.
Does anyone know the answer to this.
Thanks in advance
David
Use the integers instead of strings. Excel interprets your strings as... well... strings, and not numbers. Change your strings to numbers like this:
=IF(A1=10,600,0)
This should work and it should justify right again.

Creating a set matrix size

I have results which are 6 columns long however have been printed as 2 then 3 beneath then 1 beneath that! There are hundreds of lines and matlab will not except the structure of the matrix as it is now. Is there any way to tell matlab i want the first 5 results in their own columns then continuing down the rows after that?
My results appear as follows:
0.5 0
0.59095535915335684063 -0.59095535915335395405 -5.89791913085569763
33e-08
... repeated alot
thansk so much, em xx
I would just do a format shortE before you process the output, this will give you everything in scientific notation with 4 digits after the decimal. That 'should' allow you to fit your columns all in one line, so you don't have to deal with the botched output.
In general you should not want the output to be in a too specific format, but suppose you have this matrix:
M =[0.5 0 0.59095535915335684063 -0.59095535915335395405 -5.89791913085569763 33e-08];
To make it an actual matrix I will repeat it a bit:
M = repmat(M,10,1);
Now you can ensure that all six columns will fit on a normal screen by using the format.
format short
Try help format to find more options. Now simply showing the matrix will put all columns next to eachother. If you want one column below, the trick is to reduce your windows width untill it can only hold five columns. Matlab will now print the last column below the first.
M % Simply show the matrix
% Now reduce your window size
M % Simply show it again
This should help you display the numbers in matlab, if you want to process them further you can consider to write them to a file instead. Try help xlswrite for a simple solution.

Random Number in Octave

I need to generate a random number that is between .0000001 and 1, I have been using rand(1) but this only gives me 4 decimal points, is there any other way to do this generation?
Thanks!
From the Octave docs:
By default, Octave displays 5 significant digits in a human readable form (option ‘short’ paired with ‘loose’ format for matrices).
So it's probably an issue with the way you're printing the value rather than the value itself.
That same page shows the other output formats in addition to short, the one you may want to look in to is long, giving 15 significant digits.
And there is also the output_precision which can be set as per here:
old_val = output_precision (7)
disp (whatever)
old_val = output_precision (old_val)
Set the output_precision to 7 and it should be ok :)
Setting the output precision won't help though because the number can still be less than .0000001 in theory but you will only be displaying the first 7 digits. The simplest way is:
req=0;
while (req<.0000001)
req=rand(1);
end
It is possible that this could get you stuck in a loop but it will produce the right number. To display all the decimals you can also use the following command:
format long
This will show you 15 decimal places. To switch back go:
formay short