Replacing Rows or Columns using Indexing (or efficient too solutions) instead of “Cat ”
Show older comments
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.
- The code loads the data on Matlab
- It extracts ax ay az
- Call a funcion that convert from byte to m/s^2
- It define the all the columns to be concatenated
- It concatenates the all the columns
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!
Accepted Answer
More Answers (2)
Jan
on 17 May 2017
0 votes
You code looks fine already. I assume reading the CSV file will take much more time. Guillaume's suggestion is a little bit nicer, perhaps it runs some milliseconds faster.
If you do not need the original value of logmpu6050, overwriting this array instead of creating newlogmpu6050 might be a further step.
Andrea Ciufo
on 24 May 2017
0 votes
Categories
Find more on Large Files and Big Data in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!