How to add labels to the LEFT of a table

조회 수: 14 (최근 30일)
Amanda
Amanda 2021년 4월 25일
댓글: Star Strider 2021년 4월 26일
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

채택된 답변

Star Strider
Star Strider 2021년 4월 25일
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
Amanda
Amanda 2021년 4월 25일
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 2021년 4월 26일
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.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Tables에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by