Info
This question is closed. Reopen it to edit or answer.
Why do I get different responses when I run a piece of inside a function or directly in the command window?
1 view (last 30 days)
Show older comments
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 Comments
dpb
on 25 May 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... :)
Answers (1)
Walter Roberson
on 25 May 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 Comments
This question is closed.
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!