-1

I have a matrix that contains numerical data. Size being 31x48. I am wanting to add a label to each row of this matrix. The best way i can think of is to convert my matrix to a cell array with each row containing my 48 pieces of data.

I am unsure about how to program this so it iterates through each row adding a label such as 'Day 1' and then containing my data. I want it to look like the following: Day 1 [30 30 30 30 30 .......] Day 2 [30 30 30 30 30 ...] etc.

I need the label to be assigned to the row so that when I split it into two groups I know what data corresponds to what day.

1 Answers1

0

We'll start from your original <31x48> matrix. We'll call it 'mat'

mat=rand([31,48])

At first, we convert the matrix to cell array

mat_cell=num2cell(mat,2)

This will create a <31x1 cell>. mat_cell{day,1} will return you the 48 items for that day number. Now we'll add labels to the second column of mat_cell (1st column contains your <1x48> data). Suppose we have a labels name cell array of size <1x31> such that

labels={'Day 1' ; 'Day 2' ; 'Day 3' ; ... 'Day 31'}

then

mat_cell(:,2)=labels

should add labels to each row of mat_cell. Then

mat_cell{day,1} returns the <1x48> array for the 'day'.
mat_cell{day,2} returns label for the 'day'.

Please Note: Although it is quite evident, the labels cell array should have text arranged in correspondence to the columns in your original mat array.

Naisheel Verdhan
  • 4,905
  • 22
  • 34