Azzera filtri
Azzera filtri

how to solve the error comes in line 25

2 visualizzazioni (ultimi 30 giorni)
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.

Risposta accettata

Voss
Voss il 5 Mag 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 Commenti
Prabhath Manuranga
Prabhath Manuranga il 5 Mag 2024
Spostato: Dyuman Joshi il 5 Mag 2024
Thanks for your support Mr. Voss
Voss
Voss il 5 Mag 2024
You're welcome!

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Numeric Types in Help Center e File Exchange

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by