Issue transposing a matrix inside of a timeseries

3 ビュー (過去 30 日間)
Andrew
Andrew 2025 年 7 月 23 日
編集済み: dpb 2025 年 7 月 26 日
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!

採用された回答

dpb
dpb 2025 年 7 月 23 日
編集済み: dpb 2025 年 7 月 23 日
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 件のコメント
Andrew
Andrew 2025 年 7 月 24 日
Hi again,
So i did get what I want in the end thanks to this last message. By writing
Rk = timeseries(parentDataset.reflectometry.density',parentDataset.reflectometry.time(1));
Which shouldve been the right thing to do all along since data is measured within 1 time step and not 7. But using one element, like you advised, nade ne realize this and it fixed the issue, so thank you A LOT. I really appreciate your help!
dpb
dpb 2025 年 7 月 24 日
編集済み: dpb 2025 年 7 月 25 日
Ah! Then the supposition of one observation turns out to be correct, after all. Kewl. Glad to have been able to help; I don't quite understand the reason underlying the behavior of creating the 3D array instead that is somewhat confusing.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeSources についてさらに検索

タグ

製品


リリース

R2025a

Community Treasure Hunt

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

Start Hunting!

Translated by