フィルターのクリア

how to get rid of error using find too many input arguments?

4 ビュー (過去 30 日間)
LM
LM 2017 年 11 月 23 日
回答済み: LM 2017 年 11 月 23 日
[find(stock.permno)]==notrading(1);
for i=1:18522
end
for j=10137
newt(find(toremove(i)==c),:)=[];
end
  1 件のコメント
Stephen23
Stephen23 2017 年 11 月 23 日
編集済み: Stephen23 2017 年 11 月 23 日
Note that find is not required: just use logical indexing.

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

採用された回答

Walter Roberson
Walter Roberson 2017 年 11 月 23 日
In the command
[find(stock.permno)]==notrading(1);
if stock is a non-scalar structure, then it will undergo structure expansion; https://www.mathworks.com/help/matlab/matlab_prog/comma-separated-lists.html#br2js35-6 becoming the equivalent of
[find(stock(1).permno, stock(2).permno, stock(3).permno ..., stock(end).permno)] == notrading(1);
The find command cannot have more than three arguments; https://www.mathworks.com/help/matlab/ref/find.html so if stock() is a structure array with more than three elements, the structure expansion would lead to more than three arguments in the find() call.
Possibly you want
find([stock.permno])==notrading(1);
This would be the equivalent of
find(horzcat(stock.permno))==notrading(1);
which would still be structure expansion but horzcat() allows any number of arguments and tries to put them together into rows. The [stock.permno] would create rows or 2D arrays, depending on the shape of the permno elements.
find() applied to that would give the indices of all of the non-zero values of that list.
The == operator applied to that list would compare all of those indices to the scalar value notrading(1) . A logical result, true or false, would result for each index.
Having computed the list of true and false values, you then throw all of them away without storing them or displaying them. So unless you are doing timing tests, you might as well not have computed this value.
  2 件のコメント
LM
LM 2017 年 11 月 23 日
thank you, used first option
find([stock.permno])==notrading(1);
but now i have another error on
newt(find(toremove(i)==c),:)=[];
Walter Roberson
Walter Roberson 2017 年 11 月 23 日
You have not posted anything about the size of newt, so we do not know.
As Stephen indicates it is better to use logical indexing:
newt(toremove(i)==c, :) = [];
Did you notice that you have
for i=1:18522
end
which is the empty "for" loop? After that loop, the value of "i" will be left at its last value, 18522. Then your "for j"
for j=10137
newt(find(toremove(i)==c),:)=[];
end
is going to be equivalent to
for j = 10137
newt(toremove(18522)==c,:) = [];
end
Does toremove have that many elements? And notice that if you were to extend that for, like
for j = 1 : 10137
newt(toremove(18522)==c,:) = [];
end
then you would be removing (or not removing) the same location in newt many times, each time with the elements afterwards "falling down" to fill the hole, like columns in tetris, until eventually there was nothing left afterwards to delete...

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

その他の回答 (1 件)

LM
LM 2017 年 11 月 23 日
Thank you for all your help! I have fixed it!

カテゴリ

Help Center および File ExchangeMatrices and Arrays についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by