Hi there, novice user so please forgive any errors. Using Matlab R2022a. I have a large table (7x1516) and a cell (1x1516) with what I want to be the variable names for the table. It is obviously too big to just do normal VariableNames, is there a way to just merge these two to make the contents of the cell be the header of the table? Thanks!

 채택된 답변

Matt J
Matt J 2022년 5월 12일
편집: Matt J 2022년 5월 12일

0 개 추천

As a simplified example,
T=array2table(rand(4,5)); %A randomly generated table
T = 4×5 table
Var1 Var2 Var3 Var4 Var5 _______ _______ _______ _______ ________ 0.74225 0.40712 0.24696 0.29999 0.087221 0.65439 0.73105 0.69865 0.1184 0.023813 0.84447 0.36567 0.97351 0.77847 0.44329 0.42092 0.66762 0.91108 0.32112 0.81036
Headings={'dog','cat','fish','fox','hamster'}; %desired column headings
T.Properties.VariableNames=Headings %add the headings
T = 4×5 table
dog cat fish fox hamster _______ _______ _______ _______ ________ 0.74225 0.40712 0.24696 0.29999 0.087221 0.65439 0.73105 0.69865 0.1184 0.023813 0.84447 0.36567 0.97351 0.77847 0.44329 0.42092 0.66762 0.91108 0.32112 0.81036

댓글 수: 5

MARTINA ROGERS
MARTINA ROGERS 2022년 5월 12일
That worked to rename my variables in the table, but now every cell is displaying '1x1 table'? When I open the cell in its own tab it still has the values, but is there any way to actually view the data in the table? Thanks!
Matt J
Matt J 2022년 5월 12일
편집: Matt J 2022년 5월 12일
I suggest attaching the original table in a .mat file, and also the cell vector with the desired headings.
MARTINA ROGERS
MARTINA ROGERS 2022년 5월 12일
This is currently within a script that I need to be streamlined, so I would like to avoid that if possible. I don't really care so much if it is displaying the 1x1 table text instead of actual values, but I think it is interfereing with plotting the data. When I try to plot it ( plot(table.variablename) ) I get the error "When table is the second input, the first input must be a valid parent.". Is this an easy mistake I'm getting wrong, or is it because of the 1x1 table display?
MARTINA ROGERS
MARTINA ROGERS 2022년 5월 12일
Nevermind, I figured it out thanks!
BILAL
BILAL 2022년 11월 9일
how'd you figure this out, I'm getting the error "When table is the second input, the first input must be a valid parent"

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Annotations에 대해 자세히 알아보기

태그

질문:

2022년 5월 12일

댓글:

2022년 11월 9일

Community Treasure Hunt

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

Start Hunting!

Translated by