Matlab function deprecates its inputs
1 次查看(过去 30 天)
显示 更早的评论
I made a function like this
function param_init(iID)
disp(iID)
end
When I run the function by using the inputs
param_init('ExternalSubject')
The function does not print anything.
In fact, when I pause the execution and identify 'iID', iID was not exactly 'ExternalSubject'. Instead,
K>> iID
iID =
ExternalSubject'
Why is that?
I met this problem after using MATLAB 2021b.
Please help me!
0 个评论
采纳的回答
John D'Errico
2021-12-14
编辑:John D'Errico
2021-12-14
Your function is copied below. Answers actually uses R2021b, so we can test your assertion here.
param_init('ExternalSubject')
And so your assertion is proven to be incorrect. What you actually did we cannot know.
I'll try it by passing in the string you claim it to be. We can do this in several ways.
param_init('ExternalSubject''')
param_init("ExternalSubject'")
In each of these cases, param_init still works as it was written to work. In these cases, there is an extra single quote at the end, but disp has no problem.
So all cases worked with no problem. And this done in R2021b. Possibly you have overloaded the function disp? Is there something more to param_init that you are not showing us?
function param_init(iID)
disp(iID)
end
One thing you might try is in the debugger. What is the ascii representation of the characters in that variable? So you might try this:
+iID
That will convert the string into ascii equivalents. In this case, if I do that operation, I will expect to see:
iID = 'ExternalSubject';
+iID
ans =
69 120 116 101 114 110 97 108 83 117 98 106 101 99 116
So if you hve some unprintable character in there, we can learn what it is.
The unary + operator does not work on string objects, but you claim to have passed in a vector of characters.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Characters and Strings 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!