Error "Argument must contain a string"

2 次查看(过去 30 天)
Ken
Ken 2015-12-7
回答: Arnab Sen 2015-12-29
I am trying to code a program to find the least path for a robot but get above error. My code is:
while(currentCell ~= SearchStart)
%Take the cell where you are right now and its 8 neighbours, and store it in a variable
u=currentCell(1);
v=currentCell(2);
neighborhood8 = SearchSolution(v-1:v+1, u-1:u+1);
%Assign an Inf value to the cell you are on right now, so that it doesn't interfere when finding the minimum of the neighborhood array
neighborhood8(2,2) = Inf;
%end
%end
%Find the minimum element and its index in the 8-neighborhood
[path(i+1,1), path(i+1,2)] = find(neighborhood8==min(min(neighborhood8)));
%Increment the index of the OptimalPath array last element
i = i + 1;
end
OptimalPath = path;

回答(1 个)

Arnab Sen
Arnab Sen 2015-12-29
I understand that you are getting an error while trying to execute the code. This kind of issue might arises while there is a naming conflict among the user defined function or variable and in built function or variable.
I notice that in your code you use 'path' as a 2-D matrix. But MATLAB has an inbuilt function 'path' which accepts string. I suspect MATLAB treats your 'path' matrix as 'path' function call and throws an error as it does not get a string as input argument. Try change the name of the matrix 'path' some other variable. You can verify which function/variable is considered by MATLAB by executing the following command in MATLAB command window:
>>which -all path

类别

Help CenterFile Exchange 中查找有关 Resizing and Reshaping Matrices 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by