Azzera filtri
Azzera filtri

why am i getting this message: "Array indices must be positive integers or logical values."?

1 visualizzazione (ultimi 30 giorni)
clc
close all
clear all
abs_val = 978741.3548; %absolute value for the base station
ic = 0.1008; %instrument constant
df = xlsread('data_sheet.xlsx');
values = df(:,9);
dtime = df(:,11);
dr_rate = (values(19)-values(1))/(dtime(19)-dtime(1)); %drift rate
c = dr_rate * dtime; %correction
x = values - c; %drift corrected value
del_g = (values(1) - x) * ic;
ab_val = abs_val + del_g;
deg = df(:,1);
min = df(:,2);
sec = df(:,3);
% latitude in radian
lat_rad = (deg + (min/60) + (sec/3600))*(22/7)/180;
gt = 978031.846*(1 + 0.005278895*(sin(lat_rad)).^2 + 0.000023462*(sin(lat_rad)).^4); %theoretical value of g
%latitude correction
del_s = (lat_rad(1) - lat_rad)*(180/(22/7))*111;
lat_corr = 0.811*sin(2*lat_rad).*del_s;
%free air correction
elevation = df(:,7);
fa_corr = 0.3086 * elevation;
%bouguer correction
b_corr = 0.112 * elevation;
%bouguer anomaly
ba = ab_val - gt + lat_corr + fa_corr - b_corr;
%free air anomaly
fa_a = ab_val - gt + lat_corr + fa_corr;
%plotting the contour plot
lat_deg = deg + (min/60) + (sec/3600);
%logitudinal
lon_deg = df(:,4);
lon_min = df(:,5);
lon_sec = df(:,6);
long_deg = lon_deg + lon_min/60 + lon_sec/3600;
%bouguer anomaly
x1 = linspace(min(long_deg),max(long_deg),10);
y1 = linspace(min(lat_deg),max(lat_deg),10);
[X1,Y1] = meshgrid(x1,y1);
Z1 = griddata(long_deg,lat_deg,ba,X1,Y1,'v4');
[c,h] = contour(x1.y1,Z1)
clabel(c,h)
colorbar()
%free air anomaly
y2 = linspace(min(lat_deg),max(lat_deg),20);
x2 = linspace(min(long_deg),max(long_deg),20);
[X2,Y2] = meshgrid(x2,y2);
Z2 = griddata(long_deg,lat_deg,fa_a,X2,Y2,'v4');
contourf(Z2)
colorbar()
Error in gravity (line 54)
x1 = linspace(min(long_deg),max(long_deg),10);

Risposte (3)

Voss
Voss il 4 Mar 2023
min = df(:,2);
That line makes min a variable. Then when you try to take min(long_deg) on the error line, MATLAB interprets that as indexing the variable min with the index long_deg instead of using the min() function.
Avoid naming variables with the same names as functions to prevent this problem. Change the variable min to some other name.

Walter Roberson
Walter Roberson il 4 Mar 2023
deg = df(:,1);
min = df(:,2);
sec = df(:,3);
min is now a variable not a function. "minutes" and "minimum" same abbreviation.

Image Analyst
Image Analyst il 4 Mar 2023

Community Treasure Hunt

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

Start Hunting!

Translated by