Info

この質問は閉じられています。 編集または回答するには再度開いてください。

Generate table with an arbitrary number of events

1 回表示 (過去 30 日間)
Life is Wonderful
Life is Wonderful 2019 年 9 月 18 日
閉鎖済み: Life is Wonderful 2019 年 11 月 5 日
Please find the attachement for the data .
I want an arbitrary number of events all occuring at the same time on different rows, matched up against each other arbitrarily.
For example :
t1 = timetable(hours([1;2;3;4;5]), {'A';'B';'C';'D';'E'});
t2 = timetable(hours([1;2;3]), [pi; sqrt(2);log2(eps)]);
t3 = timetable(hours([1;2;3;4]), [pi; sqrt(2);log2(eps);eps('single')]);
t4 = timetable(hours([1;2;3;4;5]), [pi; sqrt(2);log2(eps);eps('single');log2(eps('single'))]);
I want to generate a table that look's in below style.
Time Var1_t1 Var1_t2 Var1_t3 Var1_t4
____ _______ _______ __________ __________
1 hr 'A' 3.1416 3.1416 3.1416
2 hr 'B' 1.4142 1.4142 1.4142
3 hr 'C' -52 -52 -52
4 hr 'D' "" 1.1921e-07 1.1921e-07
5 hr 'E' "" "" -23
Please suggest an alogorithm which can do above requirement with the attached *.mat file.
Thanks!
  2 件のコメント
Guillaume
Guillaume 2019 年 9 月 18 日
Note that for this example data with numeric values for t2, t3, and t4, the filler should probably be NaN instead of "".
For your real timetables, where all columns are strings, "" would be appropriate.
Life is Wonderful
Life is Wonderful 2019 年 10 月 20 日
編集済み: Life is Wonderful 2019 年 10 月 20 日
The thoery & implementation is explained below
% Input
t1 = timetable(hours([1;2;3;4;5]), {'A';'B';'C';'D';'E'});
t2 = timetable(hours([1;2;3]), [pi; sqrt(2);log2(eps)]);
t3 = timetable(hours([1;2;3;4]), [pi; sqrt(2);log2(eps);eps('single')]);
t4 = timetable(hours([1;2;3;4;5]), [pi; sqrt(2);log2(eps);eps('single');log2(eps('single'))]);
% implementation
s_Array = [{t1},{t2},{t3},{t4}];
% do a outerjoin
% The ordered pairs (a, b) is such that a ∈ A and b ∈ B. So, A × B = {(a,b): a ∈ A, b ∈ B}. For example,
% Consider two non-empty sets A = {a1, a2, a3} and B = {b1, b2, b3}
% Cartesian product A×B = {(a1,b1), (a1,b2), (a1,b3), ( a2,b1), (a2,b2),(a2,b3), (a3,b1), (a3,b2), (a3,b3)}.
% A = Φ or B = Φ, then, A × B = Φ i.e., A × B will also be a null set
for i = 1:numel(s_Array)
if (i==1)
jointimetable = s_Array{1} ;
else
jointimetable = outerjoin(jointimetable,s_Array{i},'Merge',true) ;
end
end
disp(jointimetable);
Generated output match required out.
Time Var1_jointimetable Var1_right Var1_jointimetable_1 Var1_right_1
____ __________________ __________ ____________________ ____________
1 hr 'A' 3.1416 3.1416 3.1416
2 hr 'B' 1.4142 1.4142 1.4142
3 hr 'C' -52 -52 -52
4 hr 'D' NaN 1.1921e-07 1.1921e-07
5 hr 'E' NaN NaN -23

回答 (0 件)

Community Treasure Hunt

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

Start Hunting!

Translated by