Matlab variable rounding issue

I have a variable (B_WD) that is a 295x4 double, which I am plotting using quiver. It is wind direction vectors ploted over time along a line.
quiver (B_WD(:,1),B_WD(:,2),B_WD(:,3),B_WD(:,4), 'k');
Varibles before code runs.......(4 lines)
738226.7222 0.0000 -0.3000 -0.8000
738226.7292 0.0000 0.2000 -0.5000
738226.7361 0.0000 0.3000 -0.5000
738226.7431 0.0000 0.3000 -1.1000
The first column is the position on x-axis (I am plotting the arrows along a line -hence the zeros in column 2).
When I run the code the first column switches to less precision, rounding to 2dp and some arrows plot from the same start point
Variable after code runs......see rounding
738226.7200 0.0000 -0.3000 -0.8000
738226.7300 0.0000 0.2000 -0.5000
738226.7400 0.0000 0.3000 -0.5000
738226.7400 0.0000 0.3000 -1.1000
I have been reading the help and have tried changing the format of the variable to 'long', I have replaced numbers and re-saved, nothing seems to stop this.
Advice greatly appreciated

3 个评论

format long
A = [738226.7222 0.0000 -0.3000 -0.8000
738226.7292 0.0000 0.2000 -0.5000
738226.7361 0.0000 0.3000 -0.5000
738226.7431 0.0000 0.3000 -1.1000 ]
A = 4×4
1.0e+05 * 7.382267221999999 0 -0.000003000000000 -0.000008000000000 7.382267292000000 0 0.000002000000000 -0.000005000000000 7.382267360999999 0 0.000003000000000 -0.000005000000000 7.382267431000000 0 0.000003000000000 -0.000011000000000
I don't see any change...
738226.7361 changes to 738226.7400 and 738226.7431 changes to 738226.7400 so they end up plotting at the same starting point
"When I run the code the first column switches to less precision"
You should tel us what is the code. If you don't change/assign the variable it should remain identical.

请先登录,再进行评论。

回答(1 个)

B_WD = [
738226.7222 0.0000 -0.3000 -0.8000
738226.7292 0.0000 0.2000 -0.5000
738226.7361 0.0000 0.3000 -0.5000
738226.7431 0.0000 0.3000 -1.1000 ];
quiver (B_WD(:,1),B_WD(:,2),B_WD(:,3),B_WD(:,4), 'k');
% The first column looks like datenum
datestr(B_WD(:, 1))
ans = 4×20 char array
'11-Mar-2021 17:19:58' '11-Mar-2021 17:30:02' '11-Mar-2021 17:39:59' '11-Mar-2021 17:50:03'

4 个评论

Yes they are a date number and the plot above is what they are supposed to look like. I have another data set forma different year, also as a 4 column array, and this one plots fine with no rounding. But for some reason the 2021 data automatically rounds when I plot it and when I save it. There must be a setting I am overlooking - but I cannot find it. Basically I can continually copy and past the correct numbers into the first column but as soon as I either run the quiver code to plot it or save the .mat file the values automatically round. The rounding results in some x values (arrows) overlapping. It is driving me crazy. I know there will be a simple setting somewhere that is letting this rounding happen but I cannot find it.
What is your data source? What is the format of data source?
I created this as a new variable in the work space, then copied and pasted 4 colums of data (numbers to 4dp) into the array and saved it. I am a relatively new Matlab user, as you can probably tell...
Thanks to those who have tried to help - much appreciated. A colleague has helped me resolve this problem by using the 'digits' command and 'vpa' command to set the back-ground level of precision for the variables, which has in-turn dealt with the auto-rounding....

请先登录,再进行评论。

类别

帮助中心File Exchange 中查找有关 Annotations 的更多信息

产品

版本

R2017a

Community Treasure Hunt

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

Start Hunting!

Translated by