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
  댓글 수: 1
Stelios Fanourakis
Stelios Fanourakis 2017년 9월 4일
편집: Guillaume 2017년 9월 4일
Sorry. Wrong coding
load('S_chest.mat');
load('S_abdomen.mat');
x= 'S_chest.mat';
A=zeros(5955,2);
A(1,1)=x(1);
for n= 2:5955
A(n,1)= x(n);
A(n,2)= x(n-1);
end

댓글을 달려면 로그인하십시오.

채택된 답변

Guillaume
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.

추가 답변 (2개)

Image Analyst
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().
  댓글 수: 1
Stelios Fanourakis
Stelios Fanourakis 2017년 9월 4일
I want to put the value of 5953 data out of excel that S_chest.mat contains into the X coefficient. How do I do?

댓글을 달려면 로그인하십시오.


Stelios Fanourakis
Stelios Fanourakis 2017년 9월 4일
Yeah. How do I assign all of 5953 data that the S_chest.mat file containts (excel file) to X??
  댓글 수: 1
Image Analyst
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 CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by