How can I make an array using for loop?
2 ビュー (過去 30 日間)
古いコメントを表示
Hi all!
I am trying to prepare a big array by adding all the cells from Time (18x1 cell array) like this -
TimeSeries = [Time{1,1};Time{2,1};Time{3,1};Time{4,1};Time{5,1};...
Time{6,1};Time{7,1};Time{8,1};Time{9,1};Time{10,1};...
Time{11,1};Time{12,1};Time{13,1};Time{14,1};Time{15,1};...
Time{16,1};Time{17,1};Time{18,1}];
But how can I prepare the TimeSeries array without being too manual about it?
The solution doesn't necessarily have to be a for loop approach. Any other approach is welcome! :)
0 件のコメント
採用された回答
Sulaymon Eshkabilov
2023 年 2 月 15 日
It is advised to use timetable instead of timeseries(). Therefore, it is straightforward to create timetable using array2timetable(), e.g.:
A =(1:18)';
AS = seconds(rand(size(A))); % Duration
TT = array2timetable(A, 'RowTimes',AS) % TimeTable() with 18 rows and two columns
T = removevars(TT, 'A') % 18 by 1 empty TIMETABLE
% Alt. way to create timeseries is:
B =(1:18)';
TS = timeseries(B)
5 件のコメント
Sulaymon Eshkabilov
2023 年 2 月 15 日
As now you question is a bit different from the initial one. if the latter one what you want, this is how one can create a cell array with some values:
M=(1:18).';
T= cell(size(M)); % EMpty cell 18-by-1
for ii = 1:length(M)
T{ii}=M(ii); % Cell with elements from M matrix array
end
T
T{:}
Stephen23
2023 年 2 月 15 日
"I was trying to communicate with him because I thought I needed to explain my question a bit more. "
The only thing that accepting an answer communicates is that you are happy with the information given in that answer. Yet in your very first comment you wrote "Thank you for your response but unfortunately, it did not answer my question". Very confusing.
その他の回答 (1 件)
参考
カテゴリ
Help Center および File Exchange で Data Type Conversion についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!