Clear Filters
Clear Filters

how to solve the error comes in line 25

2 views (last 30 days)
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.

Accepted Answer

Voss
Voss on 5 May 2024

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

More Answers (0)

Categories

Find more on Numeric Types in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!