indexing error, out of index error

4 views (last 30 days)
Waseem Abbas
Waseem Abbas on 26 May 2022
Edited: KSSV on 26 May 2022
function [itemcontextVector] = item_contextReader
category = [];
size = [];
sdir1 = 'E:\MS Thesis\Data\RentTheRunwayDataset\';
sfile1 = 'item_category_num.csv';
xdata = dlmread([sdir1,sfile1]);
tic;
ndata = size(xdata,1) % 1=rows,
fdata = size(xdata,2); % 2 =cols
for i=1:ndata
mov = xdata(i,1);
f = xdata(i,2:fdata);
category (i,1:fdata-1) = [f];
end
itemcontextVector= [category];
toc;
this is the code, the data set has above thousand row and 2 columns, but when i try to get the number of row through "ndata = size(xdata,1) ", i got the following error:
" Index in position 1 exceeds array bounds.
Error in item_contextReader (line 20)
ndata = size(xdata,1) ,"
why this error is happining and what is the best possibe solution,? the Responce will be appreciated, thanks
:: the same line of code is working with other similiar files

Answers (1)

Walter Roberson
Walter Roberson on 26 May 2022
size = [];
size is now an empty variable
ndata = size(xdata,1)
You are trying to index the empty variable

Tags

Products


Release

R2022a

Community Treasure Hunt

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

Start Hunting!