How to solve Error - Index in position 1 is invalid. Array indices must be positive integers or logical values.

2 ビュー (過去 30 日間)
Hi, i wonder what is the problem with the script as the error showed like this "Index in position 1 is invalid. Array indices must be positive integers or logical values."
This is the script that I run:
clc;clear all;close all;
A1 = load('Mtxj_FULL_ASCENDING.txt');
A2 = load('Mtxj_FULL_DESCENDING.txt');
B1 = load('N2j1c_FULL_ASCENDING.txt');
B2 = load('N2j1c_FULL_DESCENDING.txt');
offset = 0;
A = [A1;A2];
B = [B1;B2];
B = [B(:,1:8) B(:,9)+offset B(:,10:end)];
lat1 = A(:,1); lat2 = B(:,2);
lon1 = A(:,2); lon2 = B(:,3);
mss1 = A(:,4); mss2 = B(:,9);
scatter(lon1,lat1,'.r');hold on;
scatter(lon2,lat2,'.b');hold on;
F = scatteredInterpolant(B(:,2), B(:,3), (1:size(B,1)).', 'nearest');
A_is_nearest_idx = F( A(:,1:2) );
B_closest_to_A = B(A_is_nearest_idx,:);

採用された回答

Stephan
Stephan 2020 年 11 月 27 日
編集済み: Stephan 2020 年 11 月 27 日
A1 = load('Mtxj_FULL_ASCENDING.txt');
A2 = load('Mtxj_FULL_DESCENDING.txt');
B1 = load('N2j1c_FULL_ASCENDING.txt');
B2 = load('N2j1c_FULL_DESCENDING.txt');
offset = 0;
A = [A1;A2];
B = [B1;B2];
B = [B(:,1:8) B(:,9)+offset B(:,10:end)];
lat1 = A(:,1); lat2 = B(:,2);
lon1 = A(:,2); lon2 = B(:,3);
mss1 = A(:,4); mss2 = B(:,9);
scatter(lon1,lat1,'.r');hold on;
scatter(lon2,lat2,'.b');hold on;
F = scatteredInterpolant(B(:,2), B(:,3), (1:size(B,1)).', 'nearest');
A_is_nearest_idx = F( A(:,1:2) );
% Your data is corrupt at least at pos. 2240 and 3121 - convert to integer
% data type, to fix the error
A_is_nearest_idx = uint16(A_is_nearest_idx);
B_closest_to_A = B(A_is_nearest_idx,:);
  2 件のコメント
hanif hamden
hanif hamden 2020 年 11 月 28 日
Thank you very much Sir. How to determine at which point the data is corrupted?
Stephan
Stephan 2020 年 11 月 28 日
By hand in this case. But it could also be automated.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMatrix Indexing についてさらに検索

製品


リリース

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by