With Arduino, NeoGPS and an MPU6050 i log some data on a SD Card.
On Matlab i am trasforming the accelarations from MPU6050 from the byte values to m/s^2.
I have a civil engineer back ground, so i am not very practical with coding.
I was wondering if exists a more efficient solution in particular using Indexing?
Here my dumb code
%Open the file
filename= uigetfile ('.csv');
fileID = fopen (filename);
logmpu6050 =csvread(filename);
fclose (fileID);
%Converting acceleration from Byte to m/s^2
[ax,ay,az]=convms(logmpu6050);
%Replacing the old accelaration values with the new
cat1=logmpu6050(:,1:8);
cat2=cat(2,ax,ay,az);
cat3=logmpu6050(:,13:15);
newlogmpu6050= cat(2,cat1,cat2,cat3);
Always thanks for your patience!
Because of the concatenation of ax, ay, az
in the middle, it breaks the flow that you would use for indexing into logmpu6050
so you can't use indexing entirely to create the matrix.
However if you want to do it in a single line, you could do something like:
newlogmpu6050 = [logmpu6050(:,1:8) ax ay az logmpu6050(:,13:15)];
This still performs the desired concatenation, but you're not unnecessarily calling cat
and to me this looks a lot neater.