Borrar filtros
Borrar filtros

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

4 visualizaciones (últimos 30 días)
LM
LM el 23 de Nov. de 2017
Respondida: LM el 23 de Nov. de 2017
[find(stock.permno)]==notrading(1);
for i=1:18522
end
for j=10137
newt(find(toremove(i)==c),:)=[];
end
  1 comentario
Stephen23
Stephen23 el 23 de Nov. de 2017
Editada: Stephen23 el 23 de Nov. de 2017
Note that find is not required: just use logical indexing.

Iniciar sesión para comentar.

Respuesta aceptada

Walter Roberson
Walter Roberson el 23 de Nov. de 2017
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 comentarios
LM
LM el 23 de Nov. de 2017
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 el 23 de Nov. de 2017
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...

Iniciar sesión para comentar.

Más respuestas (1)

LM
LM el 23 de Nov. de 2017
Thank you for all your help! I have fixed it!

Categorías

Más información sobre Matrices and Arrays en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by