MATLAB Answers

Error trying to get MATLAB to read dataset

조회 수: 27(최근 30일)
Triggs
Triggs 7 Apr 2020
답변: Ameer Hamza 7 Apr 2020
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

로그인 to comment.

채택된 답변

Ameer Hamza
Ameer Hamza 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'));

  댓글 수: 0

로그인 to comment.

추가 답변(0개)

이 질문에 답변하려면 로그인을(를) 수행하십시오.


Translated by