Clear Filters
Clear Filters

Matlab function deprecates its inputs

1 view (last 30 days)
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!

Accepted Answer

John D'Errico
John D'Errico on 14 Dec 2021
Edited: John D'Errico on 14 Dec 2021
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 Comment
Heeseung Lee
Heeseung Lee on 14 Dec 2021
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!

Sign in to comment.

More Answers (0)

Categories

Find more on Arithmetic Operations in Help Center and File Exchange

Products


Release

R2021b

Community Treasure Hunt

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

Start Hunting!