Matlab function deprecates its inputs
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Heeseung Lee
le 14 Déc 2021
Commenté : Heeseung Lee
le 14 Déc 2021
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 commentaires
Réponse acceptée
John D'Errico
le 14 Déc 2021
Modifié(e) : John D'Errico
le 14 Déc 2021
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.
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Characters and Strings dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!