Having trouble creating a table

I am trying to make a table of the variables T and K. both have 9 values so there should be no issue with them being different sizes.At first they were both 1 row and 9 columns, but that came up wtih a similar error. I tried reshaping them into vectors of 1 column and 9 rows, but that didnt help.
disp(' ') %putting in a space for readability
disp('Q = 8000 cal/mol') %displaying the given variables
disp('R = 1.987 cal/(mol*K)')
disp('ko = 1200 min^-1')
disp('T = 100K-500K')
disp(' ') %putting in a space for readability
disp('computing the reaction constant') %solving the problem
Q = 8000;
R = 1.987;
ko = 1200;
T = 100:50:500;
disp('Reaction constant (k) = ko*e^(-Q/(R*T))')
k = ko.*exp(-Q./(R.*T));
knew = reshape(k,9,1);
Tnew = reshape(T,9,1);
TA = table(T,k) %error is in this line: Row index exceeds table dimentions

回答(1 个)

Make sure the variables you create your table with are column vectors. In this case I suspect your vectors are row vectors.
Just change this line and it should work:
TA = table(T',k');
Hope this helps!

6 个评论

Or you could use the two variables you've already got knew and Tnew.
It still returned the same error for me when I changed the line to what you suggested. i also tired using the new variables, but that also did not work and i recieved the same error
First i tried this
Q = 8000;
R = 1.987;
ko = 1200;
T = 100:50:500
disp('Reaction constant (k) = ko*e^(-Q/(R*T))')
k = ko.*exp(-Q./(R.*T));
knew = reshape(k,9,1);
Tnew = reshape(T,9,1);
TA = table(T',k')
And this is the output i got in the command window:
Q = 8000 cal/mol
R = 1.987 cal/(mol*K)
ko = 1200 min^-1
T = 100K-500K
computing the reaction constant
T =
100 150 200 250 300 350 400 450 500
Reaction constant (k) = ko*e^(-Q/(R*T))
Error using hw02a_Purvis_Garrett (line 54)
Row index exceeds table dimensions.
Then i tried
Q = 8000;
R = 1.987;
ko = 1200;
T = 100:50:500
disp('Reaction constant (k) = ko*e^(-Q/(R*T))')
k = ko.*exp(-Q./(R.*T));
knew = reshape(k,9,1);
Tnew = reshape(T,9,1);
TA = table(Tnew,knew)
And the output to the command window was the same:
Q = 8000 cal/mol
R = 1.987 cal/(mol*K)
ko = 1200 min^-1
T = 100K-500K
computing the reaction constant
T =
100 150 200 250 300 350 400 450 500
Reaction constant (k) = ko*e^(-Q/(R*T))
Error using hw02a_Purvis_Garrett (line 54)
Row index exceeds table dimensions.
I think you need to clear your table each time you run the code.
Try including:
TA = [];
before you create the table. This should reset the variable TA.
Alternatively you could use:
clear all;
at the beginning of your code to clear all variables.
Is it possible that you accidentally assigned a value to a variable named table ? What does
which table
show ?
oh! the
clear all
at the begining worked! thank you!
Walter is right: somewhere you created a variable named "table". That's the real issue.

请先登录,再进行评论。

类别

帮助中心File Exchange 中查找有关 Tables 的更多信息

产品

版本

R2018b

标签

Community Treasure Hunt

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

Start Hunting!

Translated by