negative numbers on table
6 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hi there,
I have a cell with different types, for example cellN = {43.1; -29; 'xyz'}. Want to have a table with RowNames and VariableNames, and to do that, use cell2table.
When I do cell2table(cellN) I get the following 'Warning: Out of range or non-integer values truncated during conversion to character.'
After some search, I realised that is due to the negative number -29.
How to overcome this??
Thanks Rui
0 commentaires
Réponse acceptée
Geoff Hayes
le 13 Fév 2015
Rui - I suspect that the problem is more likely due to the fact that you have included a string, 'xyz', in with your numbers. In fact, if I remove the string from your cellN example and run the code
cell2table(cellN)
there is no error (like you, I observe the same warning when I leave the string in).
I think that the idea with the table is that all columns will be of a like data type, and you are mixing numbers with strings and so that can lead to unexpected behaviour (or warnings). If you wish to create a table from a cell array, then ensure that all elements in each column of the cell are of the same data type.
2 commentaires
Geoff Hayes
le 14 Fév 2015
Rui's answer moved here
Thanks Geoff.
But try keeping the string, and replacing -29 to 29. No error is issued. I guess the problem is not the different data types.
Geoff Hayes
le 14 Fév 2015
Rui - I see your point, that works too. The full warning message (for R2014a) is
Warning: Out of range or non-integer values truncated during conversion to character.
> In container2vars at 57
In cell2table at 35
If you put a breakpoint at line 57 of containers2vars.m, where the code is
for i = 1:size(cj,2), vars_j{i} = cat(1,cj{:,i}); end
and try to execute
cat(1,cj{:,i})
you will see the warning AND an exception will be thrown
Error using cat
Dimensions of matrices being concatenated are not consistent.
Note that this error is thrown for your example of just using the 43.1 with the string. (The code catches the error and hides it so you don't see this.)
During the concatenation, there seems to be some sort of conversion to a character array due to the presence of the string, 'xyz'. So something like
char(43.1)
"works" in that it produces a value of + (for whatever reason, try it and see), yet
char(-29)
gives the warning. If no string is present then neither the warning nor the exception is thrown.
This suggests that the presence of the string is the culprit and should be removed.
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Characters and Strings dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!