Error trying to get MATLAB to read dataset
조회 수: 2 (최근 30일)
이전 댓글 표시
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
댓글 수: 0
채택된 답변
Ameer Hamza
2020년 4월 7일
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'));
댓글 수: 0
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Spreadsheets에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!