Azzera filtri
Azzera filtri

How to display a table without it showing "var1"?

19 visualizzazioni (ultimi 30 giorni)
x = datetime(2021,1,1) + caldays(0:4);
e = [1,6,3,2,8;4,5,6,7,7;2,4,7,8,6;]
e = 3×5
1 6 3 2 8 4 5 6 7 7 2 4 7 8 6
disp(x)
01-Jan-2021 02-Jan-2021 03-Jan-2021 04-Jan-2021 05-Jan-2021
t = table(x',e')
t = 5×2 table
Var1 Var2 ___________ ___________ 01-Jan-2021 1 4 2 02-Jan-2021 6 5 4 03-Jan-2021 3 6 7 04-Jan-2021 2 7 8 05-Jan-2021 8 7 6
b = t(sum(e)' == max(sum(e))',1)
b = table
Var1 ___________ 05-Jan-2021
tstring = evalc('disp(b)')
tstring =
' Var1 ___________ 05-Jan-2021 '
disp(['test',num2str(tstring),' end of test.'])
test Var1 ___________ 05-Jan-2021 end of test
I want to display it like this:
"test 05-Jan-2021 end of test."
And is there a way that i can get 5 as an variable so i can use it in other formula's?
Thanks for taking a look at my question!

Risposta accettata

Stephen23
Stephen23 il 16 Dic 2021
Modificato: Stephen23 il 16 Dic 2021
Tables are a container class: they contain data of other classes. So it is very important to distinguish between the table itself (or a subtable of it) which is a container, and the data store within the table. How to refer to parts of the table itself (i.e. to the container) vs. how to refer to its contents (e.g. numeric, text, datetime, etc.) is explained here:
Instead of trying to refer to a table itself you need to refer to the content of the table, e.g. using indexing with curly braces or by using the variable/column name:
x = datetime(2021,1,1) + caldays(0:4).';
e = [1,6,3,2,8;4,5,6,7,7;2,4,7,8,6].';
t = table(x,e)
t = 5×2 table
x e ___________ ___________ 01-Jan-2021 1 4 2 02-Jan-2021 6 5 4 03-Jan-2021 3 6 7 04-Jan-2021 2 7 8 05-Jan-2021 8 7 6
v = sum(t.e,2)
v = 5×1
7 15 16 17 21
y = max(v)==v
y = 5×1 logical array
0 0 0 0 1
sprintf('test %s end of test.',t.x(y))
ans = 'test 05-Jan-2021 end of test.'
"And is there a way that i can get 5 as an variable so i can use it in other formula's?"
Either:
d = day(t.x(y))
d = 5
d = t.x(y).Day
d = 5
Respectively:

Più risposte (0)

Categorie

Scopri di più su Tables in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by