MATLAB Answers

Index is out of range when creating 3D arrray

2 views (last 30 days)
peek-a-boo
peek-a-boo on 19 Oct 2021
Commented: peek-a-boo on 19 Oct 2021
This is a part of program code for reading csv file and creating 3D array.
But when runnig the code , the error "Index is out of range" occurs.
How is this code modified?
Providing supplementary information about this code, NUM_data = 40
list = dir(path);
list={list.name};
list = natsortfiles(list);
list = string(list);
for n = 1:length(NUM_data)
list(n);
X(:,:,n) = dlmread(list(n));
end
X_three_way = permute(X,[3 2 1]);
sample = X_three_way;

Answers (1)

Sulaymon Eshkabilov
Sulaymon Eshkabilov on 19 Oct 2021
If NUM_data = 40, then your code should sth like this one:
...
for n = 1:NUM_data
X(:,:,n) = dlmread(list(n));
end
...
  1 Comment
peek-a-boo
peek-a-boo on 19 Oct 2021
I tried your modification,
but the error "Index is out of range" occored.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!