Issue transposing a matrix inside of a timeseries
3 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Hello everyone,
Im trying to transpose a matrix defined inside of a timeseries:
Rk = timeseries(parentDataset.reflectometry.density', parentDataset.reflectometry.time);
parentDataset.reflectometry.density is a 7x1 matrix that I need to transpose to become 1x7 however its returning a 1x1x7. I tried using squeeze, reshape or permute to no avail.
I also tried transposing the matrix before feeding it inside the timeseries but I'm also meeting the same issue.
What really confuses me is that when parentDataset.reflectometry.density is a 1x7, transposing it actually returns a 7x1 matrix (and returns 2 when checking wiht ndims).
How can i fix this? And what am I misunderstnading?
Thanks for any help!
0 comentarios
Respuesta aceptada
dpb
el 23 de Jul. de 2025
Editada: dpb
el 23 de Jul. de 2025
This is unavoidable with the timeseries object given its internal design and restrictions on dimensions compatibilities. See the description of the input parameters for Data and Time Values. The timeseries times are always a column vector and "Either the first or the last dimension of the data must align with the orientation of the time vector."
Why, specifically, the implementation chooses to use the 3D array by plane here instead of just ignoring the row vector and forcing the column vector for the data series as it does for the time data I don't know, but that's how it's implemented and is nothing can be done about it (other than not trying to do the impossible, anyway).
The following is the constructor for the timeseries object that results in the given orientation if the input data is a row vector --
...
size_data = size(data);
if length(size_data)==2 && size_data(end)==len && size_data(1)~=len && len > 1
data = reshape(data,[size_data(1:end-1) 1 len]);
end
If size_data is [1,7] as in your example, then size_data(1:end-1) --> |size_data(1:2-1) --> size_data(1) == 1 and the resulting expression is
data = reshape(data,1 1 7);
Why do you think you need to transpose the data array, anyway? Each observation should go with each time value; if you're trying to create a multiple-variable timeseries, then it would need to be 2D array of however many variables by the length of the time vector.
Personally, I've found the timeseries to be more trouble than its worth with the peculiarities of its interface and usage; unless you've found the one particular usage that does happen to fit, I'd suggest using the timetable object instead.
11 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre Sources en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!