フィルターのクリア

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

2 ビュー (過去 30 日間)
dee
dee 2011 年 1 月 21 日
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 Center および File ExchangeSpreadsheets についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by