How do I extract the first 25% of data? Matlab help

9 views (last 30 days)
I was asked to extract the first 25% of the data that I was given. For instance the dimensions of w is equal to 1 by 900. Also, I am not to hard code the range for extraction but instead base the range of the length of the data. (so it should work whether w is 1by900 or 1by50)..

Answers (1)

Mahesh
Mahesh on 7 Sep 2014
I hope you are trying to get the 25 percent of data out of number of data you have. If you have n = 900 datapoint, the following codes might help say you have data is the vector
ndata = size(data, 2) % number of data points
p = 25; percent of data
%compute number of data points you wants
newpoints = floor(ndata*p/100);
%turn row vecror to column vector so that you wont get confused
data = data(:);
newdata = data(1:newpoints); % this will be your new extracted data points
This is the case of one dimensional vector. I hope you can recode for multidimensional in similar way. Good luck Mahesh

Community Treasure Hunt

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

Start Hunting!