Create a series of vector with different name

6 vues (au cours des 30 derniers jours)
elena galvano
elena galvano le 1 Oct 2020
Commenté : Jon le 1 Oct 2020
I have a vector list of data and i want to subdivided this vector in sub vector that contains data for each interval of ten minutes. In the first vector the data is like this '161724' that is 16:17:24 hh/mm/ss. i want to assign the name of the vectors for example vec_number from 1 to 144 in a loop. How i can do this?
  2 commentaires
Stephen23
Stephen23 le 1 Oct 2020
Modifié(e) : Stephen23 le 1 Oct 2020
"i want to assign the name of the vectors for example vec_number from 1 to 144 in a loop."
Putting meta-data (e.g. pseudo-indices) into variable names will force you into writing slow, inefficient, complex, obfuscated, buggy code that is difficult to debug. Read this to know more:
The simple and efficient alternative is to use indexing.
Jon
Jon le 1 Oct 2020
In case the motivation wasn't clear, Steven's comment explains why I had earlier provided an indexing approach in my answer below

Connectez-vous pour commenter.

Réponses (3)

KSSV
KSSV le 1 Oct 2020
Modifié(e) : KSSV le 1 Oct 2020
s = '161724'
v = [s(1:2),':',s(3:4),':',s(5:6)]
If array
s = ['161724'; '161725'; '161726'] ;
k = repelem(":",size(s,1),1)
v = [s(:,1:2),k,s(:,3:4),k,s(:,5:6)]

Jon
Jon le 1 Oct 2020
Modifié(e) : Jon le 1 Oct 2020
I would suggest rather than naming your subvectors, you reorganize your data to put it into a matrix where each column is one of your 10 minute subvectors. Assuming for example if your original data is in vector, x, and your sample rate is given by pointsPerMinute, you could do this with
intervalLength = 10; % 10 minute intervals
numPoints = length(x)
samplesInInterval = pointsPerMinute*intervalLength
numIntervals = numPoints/samplesInInterval;
X = reshape(x,samplesInInterval,numIntervals)
Then if you wanted for example the data in the third interval you could get it using
xInterval = X(:,3)
  3 commentaires
Jon
Jon le 1 Oct 2020
If the number of data points in each interval is different you could save the data in a structure indexed by interval. So something like data(1).values, data(2).values etc where the index is the interval number, so data(1).values is a vector, and data(2).values is vector but not necessarily of the same length.
Jon
Jon le 1 Oct 2020
Steven Lord's suggestion is also a very good approach

Connectez-vous pour commenter.


Steven Lord
Steven Lord le 1 Oct 2020
If you have time and/or date based data, consider storing it in a timetable array. Then you can access data from a certain range of times with timerange or resample the data with retime and/or synchronize.

Catégories

En savoir plus sur Logical dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by