Attempted to access x(12); index out of bounds because numel(x)=11.
1 次查看(过去 30 天)
显示 更早的评论
What's wrong with this line A(n,1)= x(n); ?? I find it perfectly correct.
x = load('S_chest');
y = load('S_abdomen');
for i= 1:length(y)
w= [y(i)/(x(i)+x(i-1))];
y(i)= x(i)*w*1+x(i-1)*w*2;
end
采纳的回答
Guillaume
2017-9-4
For your first piece of code, nothing guarantees that x is the same length as y.
For your second piece of code, you assign the char array 'S_chest.mat' of length 11 to x (so x(1) is simply 'S', x(2) simply '_', etc.), so of cource accessing x(12) is an error. Not sure what you meant to do.
0 个评论
更多回答(2 个)
Image Analyst
2017-9-4
编辑:Image Analyst
2017-9-4
The code you posted has nothing to do with what is apparently giving the error. x and y are structures returned from load (not arrays), and your code has no "n" index. The error says it all. In
A(n,1)= x(n);
you're passing n equal to 12 and x only has 11 elements. So there is no 12th element of x. Note: this x is different than the structure returned from load().
Stelios Fanourakis
2017-9-4
1 个评论
Image Analyst
2017-9-4
Looks like you've got that figured out since you've accepted an answer. Or do you still have a problem. If you still have a problem, attach the two .mat files.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Matrix Indexing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!