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

1 vue (au cours des 30 derniers jours)
dee
dee le 21 Jan 2011
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.

Réponse acceptée

Paulo Silva
Paulo Silva le 21 Jan 2011
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))]';

Plus de réponses (0)

Catégories

En savoir plus sur Data Import from MATLAB dans Help Center et File Exchange

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by