I want to insert a matrix into RowNames that exist in a table.

1 view (last 30 days)
h=[2,4,6,8,10,12,14,20,30,50,100,1000]';
t=[2,4,6,8,10,12,14,16,18,20];
u=h*t;
q=strcat("T=",num2str(t'))';
p=strcat("H=",num2str(h))';
array2table(u, 'VariableNames',{num2str(q)},'RowNames',{num2str(p)})
hello.
I want to put a matrix into array2table as VariableNames,RowNames.
The code is an example.
I don't know what the problem is.
I've included a picture of the shape I want in the picture below.
The values of t and h and the size of the matrix can change, so simply do not do the code below.
result_ramda=array2table(ramda, 'VariableNames',{'T=2' 'T=4' 'T=6' 'T=8' 'T=10' 'T=12' 'T=14' 'T=16 ' 'T=18' 'T=20'},'RowNames',{'h=2' 'h=4' 'h=6' 'h=8' 'h=10' 'h=12' 'h = 14' 'h=20' 'h=30' 'h=50' 'h=100' 'h=1000'})
t and h are always of the form 1x Y or Yx1.

Accepted Answer

VBBV
VBBV on 7 Dec 2022
h=[2,4,6,8,10,12,14,20,30,50,100,1000]';
t=[2,4,6,8,10,12,14,16,18,20];
u=h*t;
q=strcat("T=",string(t'))';
p=strcat("h=",string(h))';
array2table(u, 'VariableNames',string(q),'RowNames',string(p))
ans = 12×10 table
T=2 T=4 T=6 T=8 T=10 T=12 T=14 T=16 T=18 T=20 ____ ____ ____ ____ _____ _____ _____ _____ _____ _____ h=2 4 8 12 16 20 24 28 32 36 40 h=4 8 16 24 32 40 48 56 64 72 80 h=6 12 24 36 48 60 72 84 96 108 120 h=8 16 32 48 64 80 96 112 128 144 160 h=10 20 40 60 80 100 120 140 160 180 200 h=12 24 48 72 96 120 144 168 192 216 240 h=14 28 56 84 112 140 168 196 224 252 280 h=20 40 80 120 160 200 240 280 320 360 400 h=30 60 120 180 240 300 360 420 480 540 600 h=50 100 200 300 400 500 600 700 800 900 1000 h=100 200 400 600 800 1000 1200 1400 1600 1800 2000 h=1000 2000 4000 6000 8000 10000 12000 14000 16000 18000 20000
  2 Comments
Stephen23
Stephen23 on 7 Dec 2022
Simpler:
h = [2;4;6;8;10;12;14;20;30;50;100;1000];
t = [2,4,6,8,10,12,14,16,18,20];
u = h*t;
a = array2table(u, 'VariableNames',"T="+t,'RowNames',"H="+h)
a = 12×10 table
T=2 T=4 T=6 T=8 T=10 T=12 T=14 T=16 T=18 T=20 ____ ____ ____ ____ _____ _____ _____ _____ _____ _____ H=2 4 8 12 16 20 24 28 32 36 40 H=4 8 16 24 32 40 48 56 64 72 80 H=6 12 24 36 48 60 72 84 96 108 120 H=8 16 32 48 64 80 96 112 128 144 160 H=10 20 40 60 80 100 120 140 160 180 200 H=12 24 48 72 96 120 144 168 192 216 240 H=14 28 56 84 112 140 168 196 224 252 280 H=20 40 80 120 160 200 240 280 320 360 400 H=30 60 120 180 240 300 360 420 480 540 600 H=50 100 200 300 400 500 600 700 800 900 1000 H=100 200 400 600 800 1000 1200 1400 1600 1800 2000 H=1000 2000 4000 6000 8000 10000 12000 14000 16000 18000 20000

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!