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!

采纳的回答

John D'Errico
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')
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''')
ExternalSubject'
param_init("ExternalSubject'")
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.
  1 个评论
Heeseung Lee
Heeseung Lee 2021-12-14
When I copy 'ExternalSubject' and paste it to Microsoft Word, I found that there was an unseen character in front of 'E' by MATLAB but can be seen by Word. So, when I rewrite 'ExternalSubject' in the input of the function, now the function worked well. Thanks John for your kind consideration!

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Arithmetic Operations 的更多信息

产品


版本

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by