When I convert my data which is available in structure format to table it accuracy decreases
2 次查看(过去 30 天)
显示 更早的评论
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 个评论
Ive J
2020-12-16
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
2020-12-16
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.
回答(1 个)
Walter Roberson
2020-12-16
编辑:Walter Roberson
2020-12-16
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]
class(val)
What shows up for
unique( varfun(@class, T, 'output', 'cell') )
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Data Type Conversion 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!