Info
Diese Frage ist geschlossen. Öffnen Sie sie erneut, um sie zu bearbeiten oder zu beantworten.
Why do I get different responses when I run a piece of inside a function or directly in the command window?
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentare
dpb
am 25 Mai 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... :)
Antworten (1)
Walter Roberson
am 25 Mai 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 = {};
0 Kommentare
Diese Frage ist geschlossen.
Siehe auch
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!