Sub-scripted Dimension Mismatch Error

조회 수: 1 (최근 30일)
Ibro Tutic
Ibro Tutic 2016년 5월 25일
댓글: Ibro Tutic 2016년 5월 25일
I am trying to create a table, with range breakpoints along the left hand vertical axis (starting at the 2nd row of the matrix a). But I can't seem to figure this error out.
I first create an empty matrix a.
a=[];
Then I try to assign these values, starting at the 2nd row
range = [0 35 70 100 135 170 200 230 260 300]';
by using the following command
a(2:end,1) = range;
Now, shouldn't this assign the values of range, beginning at the second row of a, instead of the first? I get the error
Subscripted assignment dimension mismatch.
Any thoughts?

채택된 답변

Todd Leonhardt
Todd Leonhardt 2016년 5월 25일
At the moment you are attempting to assign something to the 1st column row a (starting at the 2nd row), but a is a matrix of double precision floating-point numbers of dimensions 0 x 0. It doesn't have any data in it at all. So you are effectively attempting to assign things to memory which hasn't been allocated yet.
Now, if a already had a matrix where the in the first column was of sufficient size, then you could do this.
I don't know what you are trying to achieve with these "range breakpoints". Maybe you could use nan (not-a-number) values in their place?
  댓글 수: 2
Ibro Tutic
Ibro Tutic 2016년 5월 25일
I am creating a table, with the above breakpoints along the vertical axis (starting from the 2nd row to the end, in the first column) and I have another set of breakpoints that create the horizontal axis of the table (along the top) starting at the 2nd column, to the end, in the first row.
Ibro Tutic
Ibro Tutic 2016년 5월 25일
I fixed the issue by initializing the matrix a by
a = zeroes(11,11)
Which was what you essentially suggested. Thanks.

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

추가 답변 (1개)

Walter Roberson
Walter Roberson 2016년 5월 25일
When a is [], end is 0 so 2:end is 2:0 which is empty. You are trying to write non-empty data into an empty range.
You would need
a(2:length(range)+1,1) = range;

카테고리

Help CenterFile Exchange에서 Graphics Object Programming에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by