A bit of MATLAB syntax fun
Show older comments
Just now, instead of executing the following code at the command line
>> x = 7;
>> x >= 5
I did the following typo:
>> x = 7;
>> x >- 5
Can you guess what the output was?
1 Comment
Walter Roberson
on 17 Mar 2022
Interesting. So command/function equivalence does not look for variables with the given name.
Answers (3)
Matt J
on 17 Mar 2022
0 votes
Unrecognized function x?
Image Analyst
on 17 Mar 2022
0 votes
I'd say true. I think it ignores the space between the negative sign and the 5 and 7 is greater than -5 so the answer is true.
1 Comment
the cyclist
on 17 Mar 2022
No, I cannot guess it.
I'm even astonished, that copy&pasting ">> x = 7;" works inspite of the ">>". Is this documented?
5 Comments
the cyclist
on 17 Mar 2022
Jan
on 18 Mar 2022
Matlab's tries to guess smartly, what the user meant. Allowing the non-functional form of commands must cause ambiguities. I ran into troubles sometimes, when this interpretation changes between versions and in consequence I avoid this in productive code. I even write
axes('NextPlot', 'add')
instead of the fragile
hold on
Image Analyst
on 18 Mar 2022
I've never had trouble with hold on, and haven't noticed any difference in that from version to version. So, in my experience, it has not been "fragile".
@Image Analyst: Yes, you are right. My formulation was misleading. hold on is not and have not been fragile. I meant other command using non-functional forms.
fullfile * * % Working:
fullfile * p % Error:
I had a longer list posted in the forum, which I add here, if I find it. The interpretation of the non-functional form did change between some releases. Therefore I avoid the non-functional form although it is expected, that e.g. "hold on" will work reliably. After being tricked too often, I got stubborn.
the cyclist
on 20 Mar 2022
Categories
Find more on Functions in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!