how to get rid of error using find too many input arguments?
조회 수: 1 (최근 30일)
이전 댓글 표시
[find(stock.permno)]==notrading(1);
for i=1:18522
end
for j=10137
newt(find(toremove(i)==c),:)=[];
end
댓글 수: 1
채택된 답변
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
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개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Matrices and Arrays에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!