# Coder Structure element Size Mismatch error during subscripting

6 views (last 30 days)
Life is Wonderful on 28 Aug 2020
Edited: Life is Wonderful on 27 Oct 2020
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])
Adam Danz on 28 Aug 2020

Adam Danz on 28 Aug 2020
Edited: Adam Danz on 28 Aug 2020
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.
Life is Wonderful on 27 Oct 2020
Edited: Life is Wonderful on 27 Oct 2020

### Categories

Find more on Creating and Concatenating Matrices in Help Center and File Exchange

### Community Treasure Hunt

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

Start Hunting!

Translated by