How to add labels to the LEFT of a table

5 visualizaciones (últimos 30 días)
Amanda
Amanda el 25 de Abr. de 2021
Comentada: Star Strider el 26 de Abr. de 2021
Let's say we have a random table
T = readtable('indoors.csv');
head(T,3)
ans=3×3 table
Time Humidity AirQuality
___________________ ________ __________
2015-11-15 00:00:24 36 80
2015-11-15 01:13:35 36 80
The way we have VariableNames as'time' 'humidity' etc written, I want similar labels on the y-axis
Except instead of regular labels, I was labels like 'x[n]' and 'h[x]', but without it actually solving or giving me a concatenation error.
How can I do this?
or even just get me on the right track without doing x[n] stuff, please
This is my goal:
Time Humidity AirQuality
___________________ ________ __________
x[n] 2015-11-15 00:00:24 36 80
h[n] 2015-11-15 01:13:35 36 80

Respuesta aceptada

Star Strider
Star Strider el 25 de Abr. de 2021
I’m not certain what you want.
Experiment with this —
Time = (datetime('2015-11-15 00:00:24')+hours(0:1.1:5.5)).';
Humidity = randi([1 100],size(Time));
AirQuality = randi([1 100],size(Time));
AirTable = table(Time,Humidity,AirQuality);
AirTable.Properties.RowNames = compose('x[%d]',1:numel(Time))
AirTable = 6×3 table
Time Humidity AirQuality ____________________ ________ __________ x[1] 15-Nov-2015 00:00:24 26 35 x[2] 15-Nov-2015 01:06:24 10 30 x[3] 15-Nov-2015 02:12:24 38 85 x[4] 15-Nov-2015 03:18:24 12 93 x[5] 15-Nov-2015 04:24:24 68 79 x[6] 15-Nov-2015 05:30:24 72 69
See the documentation on compose for more information.
Alterrnatively, try this option —
AirTable.Properties.RowNames = compose('%s[n]','a'+randi([0 25],size(Time)));
.
  3 comentarios
Amanda
Amanda el 25 de Abr. de 2021
The first one worked. But I wanted custom labels for x[n] and h[n], exactly as I have written, is this possible?
I dont want x[n] to actually count...
Star Strider
Star Strider el 26 de Abr. de 2021
For only two rows, yes.
In that instance —
AirTable.Properties.RowNames = {'x[n]','h[n]'};
will work.
However, doing this —
xhvct = repmat({'x[n]','h[n]'},1,ceil(numel(Time)/2));
AirTable.Properties.RowNames = xhvct(1:numel(Time));
throws the error:
Duplicate table row name: 'x[n]'.
So, each row must have a unique row name, however you choose to define them.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Tables en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by