how to solve the error comes in line 25

2 次查看(过去 30 天)
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

更多回答(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