Why does not Matlab warn about type casting (double - uint8) or rounding
이전 댓글 표시
I read with textscan values from a CSV file, '%s%d%f%d', having four columns.
% file: 12345A;102;0.1312;1 [...]
I initalized matrix M (nan(#cols, #rows)) for some results to be computed from those values (3rd column). Then in a for-loop I made some calculations with my data (3rd column, several records). Then I saved my three numbers (mean, std, on/off value from 4th column in CSV) in a larger M matrix:
M(k, 3*m+[-2 -1 0]) = [value_mean value_std value_correct]; % e.g., M(2, [4 5 6]) = [0.1032 0.0812 1]
I got stuck because M matrix contained only integers even if all 'value_mean' and 'value_std' were non-integers.
M(2, [4 5 6]) % [0 0 1]
Only after a while I understood that textscan function reads '%d' as type 'int32', and then in the assignment (above) types of 'value_mean' and 'value_std' are magically / automatically casted to int or rounded. Matrix M itself was before and afterwards of type 'double'. Matlab didn't give any warning.
I wonder if it is possible to give a warning message in case of this kind of (necessary) casts? I understand that having no strong types brings this kinds of problems.
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!