Coder Structure element Size Mismatch error during subscripting

조회 수: 2 (최근 30일)
Hi
I am facing Size mismatch error while performing array operation with structure .I need help in resolving the issue
Impnse.isOut(:,idx) = memfcn(1:size(Impnse.f(:,idx),1),locs);
Error Message : Size mismatch ([441000 x 1] ~= [:? x 441000])
f = zeros(441000, 2)
isOut = zeros(size(f,1),2);
Input Impnse = struct('f',f ,'isOut' ,isOut);
Impnse.isOut(:,idx) = memfcn(1:size(Impnse.f(:,idx),1),locs);
size(1:size(Impnse.f(:,idx),1))
ans =
1 441000
size(locs)
ans =
1423 1
size(Impnse.isOut(:,idx))
ans =
441000 1
Size mismatch ([441000 x 1] ~= [:? x 441000])
  댓글 수: 6
Life is Wonderful
Life is Wonderful 2020년 8월 28일
Yes, that's correct but how - is not clear to me
Adam Danz
Adam Danz 2020년 8월 28일
Addressed below in my answer.

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

채택된 답변

Adam Danz
Adam Danz 2020년 8월 28일
편집: Adam Danz 2020년 8월 28일
Impnse.isOut(idx,:) = memfcn(1:size(Impnse.f(:,idx),1),locs);
% ^^^^^
This is matrix indexing 101 and it's a rudimentary concept to understand.
The size of your output is 1 x 441000 which means it's a row vector with 441000 elements.
The output Impnse.isOut(idx,:) means that you're storing the 441000 values in the row number defined by idx.
For example,
a = zeros(3,6)
a =
0 0 0 0 0 0
0 0 0 0 0 0
0 0 0 0 0 0
a(2,:) = 1:6
0 0 0 0 0 0
1 2 3 4 5 6
0 0 0 0 0 0
With Impnse.isOut(:,idx), you're storing the values in the column number defined by idx.
If the matrix does not have 441000 rows, the data won't fit.
For example,
a = zeros(3,6)
a =
0 0 0 0 0 0
0 0 0 0 0 0
0 0 0 0 0 0
a(:,2) = 1:6
Error:
Unable to perform assignment because the size of the left side is 3-by-1
and the size of the right side is 1-by-6.
However, if the matrix does have the right amount of rows, the data can be transfered to the column even if it's a row vector.
a = zeros(6,3)
a =
0 0 0
0 0 0
0 0 0
0 0 0
0 0 0
0 0 0
a(:,3) = 1:6
a =
0 0 1
0 0 2
0 0 3
0 0 4
0 0 5
0 0 6
I don't know why your error message differs. Perhaps you're using a different version of matlab or perhaps the error message is customized.
  댓글 수: 6

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by