Clear Filters
Clear Filters

When I convert my data which is available in structure format to table it accuracy decreases

4 views (last 30 days)
When I convert my data which is available in structure format to table which I requre for further plotting the values like 0.7 or 0.5 changes to 1 and 0.
I am use the command
struct2table(name);
for example
from
0.505829210007949
0.549192911465458
0.539702546882381
0.529415778849225
31.7804971641414
0.459445413396004
1.18079450595063
1.21475111433387
to
0
0
0
0
1
  2 Comments
Ive J
Ive J on 16 Dec 2020
Please provide your script along with the result you get. I cannot reproduce your output solely based on your question.
myStruct.vals = [0.505829210007949
0.549192911465458
0.539702546882381
0.529415778849225
31.7804971641414
0.459445413396004
1.18079450595063
1.21475111433387];
struct2table(myStruct)
ans =
8×1 table
vals
_______
0.50583
0.54919
0.5397
0.52942
31.78
0.45945
1.1808
1.2148
dpb
dpb on 16 Dec 2020
No, you did something else either in the display formatting or converting to a logical array or somesuch. MATLAB will retain full precision of the data in the conversion internally; there may be some slight loss of precision if you were to write to a file with high-level routines but it would still have 5-6 decimal digits of precision at worst.
You'll have to post a complete working example that reproduces the problem for folks to be able to diagnose just exactly what you did to get the symptom, but it is operator error, not MATLAB bug.

Sign in to comment.

Answers (1)

Walter Roberson
Walter Roberson on 16 Dec 2020
Edited: Walter Roberson on 16 Dec 2020
Your table contains an integer datatype. When you combine numeric datatypes in an array, the result is converted to the most restrictive datatype
val = [int8(-3) int16(555) pi]
val = 1×3
-3 127 3
class(val)
ans = 'int8'
What shows up for
unique( varfun(@class, T, 'output', 'cell') )

Categories

Find more on Numeric Types in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!