## round off problem in matlab

### Ali Asghar (view profile)

on 19 Sep 2019 at 7:08
Latest activity Commented on by Ali Asghar

### Ali Asghar (view profile)

on 23 Sep 2019 at 7:18

### Steven Lord (view profile)

I have 4 variables each have 4 values (1x4) in it and I want to store all in value in 1 variable (4x4) but values are change when i do it.
MAV = [0.0924317411754942 0.0313003411430704 0.00365072354007141 0.00332056432198707]
waveLen = [172.697769103870 68.7603283596702 69.2536410243476 63.2141284111186]
zcdOut = [560 719 6155 6260]
slope_count = [478 212 4949 4830]
HG0_extracted_feature = [waveLen; MAV; zcdOut; slope_count]
it gives
173 69 69 63
0 0 0 0
560 719 6155 6260
478 212 4949 4830
note MAV values become zero, it round off waveLen, etc values...
how i correct it?
Thank you

### Steven Lord (view profile)

on 19 Sep 2019 at 14:01

Based on that display I suspect one or both of the variables zcdOut or slope_count are stored in an integer class. When you combine data stored in an integer class with data stored in a non-integer class, "all elements of the resulting matrix are given the data type of the left-most integer".
Consider converting the variable stored in an integer class to double before combining them into one array, so that the resulting matrix is also a double.

Show 1 older comment
Stephen Cobeldick

### Stephen Cobeldick (view profile)

on 22 Sep 2019 at 11:02
Steven Lord

### Steven Lord (view profile)

on 22 Sep 2019 at 13:31
Check the types of variables using class or whos.
As Stephen Cobeldick said, to convert variables to double use the double function.
Ali Asghar

### Ali Asghar (view profile)

on 23 Sep 2019 at 7:18
thanks dear

### Raj (view profile)

on 19 Sep 2019 at 7:20

format longg
MAV = [0.0924317411754942 0.0313003411430704 0.00365072354007141 0.00332056432198707]
waveLen = [172.697769103870 68.7603283596702 69.2536410243476 63.2141284111186]
zcdOut = [560 719 6155 6260]
slope_count = [478 212 4949 4830]
HG0_extracted_feature = [waveLen; MAV; zcdOut; slope_count]

Ali Asghar

### Ali Asghar (view profile)

on 20 Sep 2019 at 11:35
Dear i have data called filter_datawindow 24000x4.
i apply functions in loop that store the value of waveLen, MAV, zcdOut, slope_count in workspace in long format but when i merge all values is give same result as
173 69 69 63
0 0 0 0
560 719 6155 6260
478 212 4949 4830
for i = 1:4
waveLen(i) = find_waveform_length(filter_datawindow(:,i))
MAV (i)=find_MAV(filter_datawindow(:,i),2.4e4)
zcdOut (i) = zcd(filter_datawindow(:,i));
slope_count (i) = find_slopSign(filter_datawindow(:,i),0.001)
end
format longg
HG0_extracted_feature = [waveLen; MAV; zcdOut; slope_count]
gives
173 69 69 63
0 0 0 0
560 719 6155 6260
478 212 4949 4830

### Matt J (view profile)

on 19 Sep 2019 at 7:28
Edited by Matt J

### Matt J (view profile)

on 19 Sep 2019 at 7:30

The values are not changed. They are just displayed to the screen to 4 decimal points. Use format long to see more precision. Also, note that all elements are premultiplied by 1000.

Ali Asghar

### Ali Asghar (view profile)

on 20 Sep 2019 at 11:37
when i merge all values it gives
173 69 69 63
0 0 0 0
560 719 6155 6260
478 212 4949 4830
172.69776910387 68.7603283596702 69.2536410243476 63.2141284111186
0.0924317411754942 0.0313003411430704 0.00365072354007141 0.00332056432198707
560 719 6155 6260
478 212 4949 4830
Matt J

### Matt J (view profile)

on 20 Sep 2019 at 14:16
As Steven. mentioned, that is probably because one of the vectors you are merging is uint8 or similar.
Steven Lord

### Steven Lord (view profile)

on 20 Sep 2019 at 16:56
Rows 3 and 4 of the resulting array have values too large for uint8 or int8 so they would need to be at least 16-bit integers.