필터 지우기
필터 지우기

how to solve the error comes in line 25

조회 수: 2 (최근 30일)
Prabhath Manuranga
Prabhath Manuranga 2024년 5월 5일
댓글: Voss 2024년 5월 5일
clear, clc
format longg
GM = 0.3986004415E+15;
alpha = 0.63781363E+07;
% Load data
%data = importdata('EGM08.txt');
data = readtable('EGM08.txt', 'ReadVariableNames', false);
% Extract sigma and beta values
sigma = data(:,5);
beta = data(:,6);
% Initialize Dw
Dw = 0;
% Calculate Dw using the equation
for n = 0:78
summation = 0;
for m = 0:2190
summation = summation + (sigma(m+1)^2 + beta(m+1)^2); % This is the line 25
end
Dw = Dw + sqrt((GM/alpha)^2 * summation);
end
% Display the result
disp(['Dw = ',num2str(Dw)]);
when running the program the following error comes.
Error using egm2008 (line 25)
Subscripting into a table using one
subscript (as in t(i)) is not
supported. Specify a row subscript and
a variable subscript, as in
t(rows,vars). To select variables, use
t(:,i) or for one variable t.(i). To
select rows, use t(i,:).
EGM08.txt have 2401334 rows and 6 columns.

채택된 답변

Voss
Voss 2024년 5월 5일

These lines make sigma and beta tables with one variable each

sigma = data(:,5);
beta = data(:,6);

which produces the error when you try to index them with one subscript, as in sigma(m+1), later on.

Instead, make sigma and beta column vectors (presumably of a numeric type):

sigma = data.(5); 
beta = data.(6);  

https://www.mathworks.com/help/matlab/matlab_prog/access-data-in-a-table.html

  댓글 수: 2
Prabhath Manuranga
Prabhath Manuranga 2024년 5월 5일
이동: Dyuman Joshi 2024년 5월 5일
Thanks for your support Mr. Voss
Voss
Voss 2024년 5월 5일
You're welcome!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Numeric Types에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by