Borrar filtros
Borrar filtros

Info

La pregunta está cerrada. Vuélvala a abrir para editarla o responderla.

Why do I get different responses when I run a piece of inside a function or directly in the command window?

1 visualización (últimos 30 días)
When I run the following piece of code (directly in the command window, for debugging purposes):
categories_hash = arrayfun(@(idx) string2hash(categories{idx}), 1:size(categories));
- it works
but when I invoke the function that contains it, I get the following error:
Cell contents reference from a non-cell array object.
Error in intellegite>@(idx)string2hash(categories{idx}) (line 22)
categories_hash = arrayfun(@(idx) string2hash(categories{idx}), 1:size(categories));
Error in intellegite (line 22)
categories_hash = arrayfun(@(idx) string2hash(categories{idx}), 1:size(categories));
  8 comentarios
Fernando Fernandes
Fernando Fernandes el 25 de Mayo de 2017
Guys, thanks for the help. With the debugging tool you have just taught me, I've found out where I was dereferencing it! ... It was in the caller function. Thank you!
dpb
dpb el 25 de Mayo de 2017
Kewl~the debugger is most powerful tool, indeed.
Demonstrates that context is important; was sure to point of near certainty that was the problem. Matlab rarely is wrong in its error diagnosis of this type... :)

Respuestas (1)

Walter Roberson
Walter Roberson el 25 de Mayo de 2017
You have
vec_cat = '';
then you have a double-nested loop that will not necessarily execute the inner code at all (because the input could be empty.)
Then you unique() this item that might still be '', after which you try to use the result of that as if it were a cell array.
You should be initializing vec_cat = {};

La pregunta está cerrada.

Community Treasure Hunt

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

Start Hunting!

Translated by