Matlab function deprecates its inputs

1 回表示 (過去 30 日間)
Heeseung Lee
Heeseung Lee 2021 年 12 月 14 日
コメント済み: Heeseung Lee 2021 年 12 月 14 日
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 Center および File ExchangeCharacters and Strings についてさらに検索

製品


リリース

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by