in this pics you see the output i want to do
i've 2 table A and B
>> size(A)
ans =
560 2
>> size(B)
ans =
188 1
i want to use array2table(A,B) to create union and later plot the table in app designer using uitable
but it gives me error
T_=array2table(A,B)
Error using array2table
Wrong number of arguments.
this error because the tables have different dimensions.. How to add blanks to the second to match lengths?

 Réponse acceptée

Image Analyst
Image Analyst le 13 Août 2023
If they have the same number of columns and you just want to stitch them together, one atop the other, try
AB = [A; B]

11 commentaires

aldo
aldo le 13 Août 2023
have the same number of columns but different number of rows
Image Analyst
Image Analyst le 14 Août 2023
Then it should work to stack the tables on top of each other, as long as the columns have the same names. Did you try it? Did I understand correctly what you want? If not, please explain better with examples of the two inputs and one output you are trying to achieve.
aldo
aldo le 14 Août 2023
Modifié(e) : aldo le 14 Août 2023
this is exactly what i want to do The 3 columns are side by side and occupy the whole table screen... the width is the same for all 3 (2 columns) while the length is different
e=[a;b;c]
Error using tabular/vertcat
Timetables and tables may be concatenated only when the timetable is first. Convert
all inputs to the same data type, or change their order.
Image Analyst
Image Analyst le 14 Août 2023
OK, so column 1 is different. For A column 1 are times but not for B and C.
If you have any more questions, then attach your data (A, B, and C in a .mat file) and code to read it in with the paperclip icon after you read this:
aldo
aldo le 14 Août 2023
Modifié(e) : Walter Roberson le 14 Août 2023
i give link because using attachment is so longer and it rejected me
>> class(a)
ans =
'string'
>> class(b)
ans =
'timetable'
>> class(c)
ans =
'timetable'
aldo
aldo le 14 Août 2023
Modifié(e) : aldo le 14 Août 2023
i try to according lenght c to b:
s=height(b)-height(c);
s1=repmat({" "},s,2);
A=timetable2table(b);
A.Properties.VariableNames={'Date','Prof'};
B=cell2table(s1);
B.Properties.VariableNames={'Date','Prof'};
T=vertcat(A,B)
but it give me an error and I think this laborious road is not correct
THIS IS MY SOLUTION (it's orrible...i'd like to learn the better version)
a,b,c
whos a
Name Size Bytes Class Attributes
a 560x2 69728 string
>> whos b
Name Size Bytes Class Attributes
b 188x1 3997 timetable
>> whos c
Name Size Bytes Class Attributes
c 16x1 1245 timetable
s=height(a)-height(b);
%end
s1=repmat({" "},s,2);
A=timetable2table(b);
%Acell=table2cell(A)
A.Properties.VariableNames={'Date','Prof'};
B=cell2table(s1);
B.Properties.VariableNames={'Date','Prof'};
A1=convertvars(A,{'Date','Prof'},'string');
T1=vertcat(A1,B)
%T1cell=[Acell,s1];
s=height(a)-height(c);
%end
s1=repmat({" "},s,2);
A=timetable2table(c);
A.Properties.VariableNames={'Date','Prof'};
B=cell2table(s1);
B.Properties.VariableNames={'Date','Prof'};
A1=convertvars(A,{'Date','Prof'},'string');
T2=vertcat(A1,B)
T1_=table2cell(T1);
T2_=table2cell(T2);
TT=[T,T1_,T2_]
T_finally=array2table(TT);
It is not possible to concatenate a string and a table or time table. You need to convert the string to a timetable.
Profit = double(a(:,2));
Data = datetime(a(:,1));
a_tt = timetable(Profit, 'RowTimes', Data);
output = [a_tt; b; c];
aldo
aldo le 14 Août 2023
Modifié(e) : aldo le 14 Août 2023
hi walter,
the problem started in a different way..there were 3 matrices to be concatenated having different lengths.. With your solution I create a timetable but I didn't concatenate the 3 arrays horizontally.
In my "T_finally" I am able to do this
(and in app designer it works)
Image Analyst
Image Analyst le 14 Août 2023
So is it all working now?
To stitch together horizontally you use commas and they all need to have the same number of rows.
To stitch together vertically you use semicolons and they all need to have the same number of columns. In addition, if the variables are tables, then I think the columns in the table must all have different field names.
There are a lot of "joining" table functions that may get around some of the restrictions I just mentioned above.
Sometimes it's better and easier to do stitching as regular double arrays before converting the array into a table. Just depends on exactly what you want to do (what output you want).
aldo
aldo le 15 Août 2023
ok thanks

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

Community Treasure Hunt

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

Start Hunting!

Translated by