필터 지우기
필터 지우기

Index out of bounds error when working with data imported from excel

조회 수: 2 (최근 30일)
I have this problem working with data I imported from excel. It did not import the way I expected. My code is like this
clear all, close all, clc
data=xlsread('Test-MATLAB.xls',-1);
data(:,5) = -99999*ones(10,1);
depth=[1:1:max(data(:,1))]';
n=numel(depth);
m=4;
for j=1:m%
for i=1:n
idx=find(data(:,1)==depth(i));
if numel(idx)==0;
data2(i,j)=-99999;
else
data2(i,j)=data(i,j);
end
end
end
data2
xlswrite('Test-MATLAB.xls',data2,'Daten2','B2')
This is the Test-MATLAB.xls
depth x y z
2 5 3 8
4 5 3 8
7 5 3 8
9 5 3 8
12 5 3 8
13 5 3 8
18 5 3 8
19 5 3 8
23 5 3 8
28 5 3 8
When I executed it the code with this data I get this error:
??? Attempted to access data(12,2); index out of bounds because size(data)=[10,5].
Error at 14
data2(i,j)=data(i,j+1);
any idea?
I also want to be able to save the data to excel when I am done.

채택된 답변

Paulo Silva
Paulo Silva 2011년 1월 21일
I believe that the error is in the line
depth=[1:1:max(data(:,1))]';
because
max(data(:,1))
will give you the value 28 and you don't have 28 lines in your data, maybe the correct version of that line is
depth=[1:numel(data(:,1))]';

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Spreadsheets에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by