Error trying to get MATLAB to read dataset

7 views (last 30 days)
I'm trying to get MATLAB to read values of K and q from the excel spread sheet named dataset(its attached) but everytime i do it I get this error (as shown below) and i dont know what to do as im quite a rookie at MATLAB
Error using solutionwithoutforcingtermorheatsource (line 39)
Subscripting into a table using one subscript (as in t(i)) or
three or more subscripts (as in t(i,j,k)) is not supported.
Always specify a row subscript and a variable subscript, as in
t(rows,vars).
for i=1:Ne
%read dataset for K and q values
K(i)= readtable('dataset.xlsx','Range','A2:A20');
q(i)= readtable('dataset.xlsx','Range','B2:20');
end
for i=1:Ne
h(i)=0.25;
A(i,i)=A(i,i)+K(i)/h(i)^2; A(i,i+1)=A(i,i+1)-K(i)/h(i)^2;
A(i+1,i)=A(i+1,i)-K(i)/h(i)^2; A(i+1,i+1)=A(i+1,i+1)+K(i)/h(i)^2;
end

Accepted Answer

Ameer Hamza
Ameer Hamza on 7 Apr 2020
First, it seems that you are reading the same data several times.
for i=1:Ne
%read dataset for K and q values
K(i)= readtable('dataset.xlsx','Range','A2:A20');
q(i)= readtable('dataset.xlsx','Range','B2:20');
end
You should just do it once
K = readtable('dataset.xlsx','Range','A2:A20');
q = readtable('dataset.xlsx','Range','B2:B20');
% ^ also note B is missing in your code
Remember that readtable returns a variable of type table. You need to access its elements using curly brackets. For example, K{3,4} will access the element in the 4th column and 3rd row of table K.
If you just want to treat the data as numeric, it is better to convert it into an array first.
K = table2array(readtable('dataset.xlsx','Range','A2:A20'));
q = table2array(readtable('dataset.xlsx','Range','B2:B20'));

More Answers (0)

Community Treasure Hunt

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

Start Hunting!

Translated by