Automating length with reshaping, and using reshape to loop through data.
7 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hello,
I currently have a 3275x1 vector, named mouse_coord_array. Each cell has three specific data points repeated many times. For instance, I’ll have a series of X-values, Y-values and T(time)-values. The data is split in the following way:
X, Y, T; X2, Y2, T2; X3, Y3, T3; X4, Y4, T4; X5, Y5, T5; X6, Y6, T6;…(and so on). In practice, it looks like this:
3.4,3.1,401232;4.6,4.2,451232; 5.2,3.1,53123; 5.4,3.5,4124214;[…](and so on).
Then, the second row will have a whole new set of numbers. The third will have another new set, and the fourth, and so on.
I’ve managed to use the following code to split the x, y and t values into individual columns for each single row:
example = mouse_coord_array(1,:)
t = split(example ,{',',';'});
t = reshape(t,[3,312])';
% I put 312 as I new the number of rows for this specific cell. However this won’t be the case for the other cells of data.
However, the amount of data in each row varies, so I won’t always want 312 rows.
I have two questions:
- How would I automate the length of t as to cater to the amount of data is in each row? This is for when I don't know what the length of my reshaped data will be.
- Once I’ve figured this out, I intend on splitting the data for each of the indiviudal 3275 rows. This is another part I’m stuck on - I can’t seem to figure out how to loop this for each row, so that the data is split into X, Y and T for each individual row of mouse_coord_array.
Any help would be greatly appreciated!
I'm fairly new to MatLab so apologies if some of my terminology is incorrect.
Thanks so much for your help!
2 commentaires
Jan
le 31 Jan 2023
"I currently have a 3275x1 vector" - 3275 is not divisable by 3. Therefore it cannot be a list of X,Y,T; ... values.
"Each cell has three specific data points" - "Cells" are elements of cell arrays. You are talking of a numerical array? Then these are "elements".
"t = split(example ,{',',';'});" - The actual input are strings or cell strings?
Réponse acceptée
Jan
le 31 Jan 2023
Modifié(e) : Jan
le 31 Jan 2023
tt = reshape(t, 3, []).'
Note: While ' is the abbreviation for ctranspose, .' is transpose. This does not change the result for real input values, but it is clearer.
Afterwards the X values are:
X = tt(:, 1)
Or with the original data:
X = t(1:3:end)
3 commentaires
Jan
le 1 Fév 2023
I'm still not sure, if I understand, what the inputs are. After:
t = split(example ,{',',';'});
t seems to be a string array. Do you want a numerical output or really cell arrays?
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Cell Arrays 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!