Coder Structure element Size Mismatch error during subscripting

2 ビュー (過去 30 日間)
Life is Wonderful
Life is Wonderful 2020 年 8 月 28 日
編集済み: Life is Wonderful 2020 年 10 月 27 日
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 件のコメント
Life is Wonderful
Life is Wonderful 2020 年 10 月 8 日
Hi Adam,
Can you please help me with below link issue ?
Thank you!
Life is Wonderful
Life is Wonderful 2020 年 10 月 27 日
編集済み: Life is Wonderful 2020 年 10 月 27 日

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by