Filter löschen
Filter löschen

how to solve the error comes in line 25

2 Ansichten (letzte 30 Tage)
Prabhath Manuranga
Prabhath Manuranga am 5 Mai 2024
Kommentiert: Voss am 5 Mai 2024
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.

Akzeptierte Antwort

Voss
Voss am 5 Mai 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

  2 Kommentare
Prabhath Manuranga
Prabhath Manuranga am 5 Mai 2024
Verschoben: Dyuman Joshi am 5 Mai 2024
Thanks for your support Mr. Voss
Voss
Voss am 5 Mai 2024
You're welcome!

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Numeric Types finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by