MATLAB Answers

Hot to take the first data values out and then plot all of data

1 view (last 30 days)
m j
m j on 11 Jul 2016
Commented: Star Strider on 12 Jul 2016
So each sample I take has 406 csv's. And I would like to leave the first six values out of the sample and then plot, just without those first 6 values. New to matlab. Any ideas?
Thanks

  0 Comments

Sign in to comment.

Answers (2)

Star Strider
Star Strider on 11 Jul 2016
There are at least three ways to deal with that, depending on the function you’re using to read your .csv files.
  1. Define the range of values to read in xlsread and csvread (see the respective function documentation),
  2. Define 'HeaderLines',6 in textscan,
  3. Read in everything and then delete the first 6 rows, regardless of the function you use to import them.

  6 Comments

Show 3 older comments
Star Strider
Star Strider on 12 Jul 2016
I didn’t see any blank spaces, but then that’s a huge file.
This seems to do what you want:
fidi = fopen('mike haag recording.txt','rt');
d = textscan(fidi, ['%*f%*f%*f%*f%*f%*f' repmat('%f', 1, 400)], 'CollectOutput',1, 'Delimiter',',');
Data = cell2mat(d);
x = 1:size(Data,2);
figure(1)
plot(x, Data)
grid
The plot:
I saved your data to that specific file because everyone names their file similarly and this keeps them separate in my computer.
m j
m j on 12 Jul 2016
perfect but I am having trouble figuring out this line.
'%*f%*f%*f%*f%*f%*f' repmat('%f', 1, 400)] so you create a string of 6 floats and then call repmat and have the first 6 floats be transferred into the 6 '%*f%*f%*f%*f%*f%*f' string?
Star Strider
Star Strider on 12 Jul 2016
Thank you.
The entire format descriptor is:
['%*f%*f%*f%*f%*f%*f' repmat('%f', 1, 400)]
In MATLAB, the square brackets when applied to strings act as a concatenation operator, here forming one string of all the elements within the brackets. The first six fields are ‘%*f’, with the asterisk telling MATLAB to ignore each of those fields. The repmat call avoids my having to type ‘%f’ 400 times to read in the 400 following values. (I could have use a repmat call for the first six fields as well, but considered that to be sort of ‘overkill’.)

Sign in to comment.


Walter Roberson
Walter Roberson on 12 Jul 2016
YourData([1:406:end, 2:406:end, 3:406:end, 4:406:end, 5:406:end, 6:406:end], :) = [];

  0 Comments

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!

Translated by