Meging two tables with different numbers of Rows

44 views (last 30 days)
Hallo,
I have two tables with different rows numbers and the final goal is to export these Data in excel File by using the Function " writetable ".
The first table contains Data of Maxima and Minima (as in the Image down). The second Table contains the increment Values of Maxima and Minima, they are always less Values and less rows than the Max.-Min.
First thing i have transfered the Data to Table as follow :
MaxMin = table(DehnungMax,DehnungMin);
Ink = table(DehnunungMax_inkr,DehnunungMin_inkr);
The Problem by using the function " outer join " asking always for Key variables, but theoretically there is no key.
I am trying even if Possible to put the increment of each Maxima and Minima under them in the same Column but divide the both Values with Header. or Even beside each other okay also. as Follow :
Thank you very much for any Help or Suggestion.

Accepted Answer

Vilém Frynta
Vilém Frynta on 29 Nov 2022
Edited: Vilém Frynta on 29 Nov 2022
Try:
% Random data to work with
DMax = [1 2 3 4 5]';
DMin = [0.1 0.2 0.3 0.4 0.5]';
DMaxInk = [11 22 33 44]';
DMinInk = [0.11 0.22 0.33 0.44]';
% Create table and create columns DMax and DMin
T = table;
T.DMax = DMax;
T.DMin = DMin;
If this is just one-time thing and you do not wish to automate this process, you can match the lengths by adding empty values.
% Adding NaN values on the end
DMaxInk(end+1,1) = NaN;
DMinInk(end+1,1) = NaN;
% Create columns for DMaxInk and DMinInk
T.DMaxInk = DMaxInk;
T.DMinInk = DMinInk
T = 5×4 table
DMax DMin DMaxInk DMinInk ____ ____ _______ _______ 1 0.1 11 0.11 2 0.2 22 0.22 3 0.3 33 0.33 4 0.4 44 0.44 5 0.5 NaN NaN
% Save the table
writetable(T,"your_table_name.xlsx");

More Answers (0)

Categories

Find more on Tables in Help Center and File Exchange

Tags

Products


Release

R2018b

Community Treasure Hunt

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

Start Hunting!