How can I hide all variables in work space to display ?
Show older comments
Hi,
I have created one script (not a function). While runnign the script , I dont want to showcase the variables in workspace.
How can I do it in matlab ? I am planning to create p.code of that lateron,
Regards,
Koustubh
1 Comment
Stephen23
on 13 Mar 2020
"How can I do it in matlab ?"
Simple: use a function, not a script.
Scripts are fun for playing around with, but I would not use them for any code that is used for longer than one day.
Answers (1)
John D'Errico
on 13 Mar 2020
Edited: John D'Errico
on 13 Mar 2020
1 vote
Um, then don't make it a script? Scripts are something worth learning to avoid as you progrees further into MATLAB anyway. But if you don't want what you write to leave behind a slew of variables, then don't make it a script!
If you will give this code to someone else, note that it will step on any variables that are already in their base workspace - a bad thing.
I did check, by the way, to verify that you can indeed p-code a script. Why, oh why would you do that, I don't know. But you can do so.
Yes, I suppose you could put one line at the end of your script, that just clears all of the variables, but why in the name of god and little green apples would you do that, when all you need to do is learn to use a function? If you did as I just said anyway, then note that if the user does have a variable with the same name as something you just created, then it will overwrite their work, and then you will delete it. This is a bad thing.
Yes. I do often create little scripts myself, usually purely as temporary things, to test out a block of code, etc. But for anything I would ever give to someone else, it would NEVER be in script form.
Just learn to use functions!!!!!!!!!
6 Comments
Koustubh Shirke
on 13 Mar 2020
John D'Errico
on 13 Mar 2020
Hey. I told you how to do it, as long as you are willing to clear all variables at the end of your script. If you don't want advice, then don't decide to do something foolish, and then ask for advice about it in a public forum.
Learn to use MATLAB.
Koustubh Shirke
on 13 Mar 2020
John D'Errico
on 13 Mar 2020
Edited: John D'Errico
on 13 Mar 2020
You asked for advice. My advice was to not use a script at all. Then I explained why not. I also offered two solutions: Either don't use a script and learn to use functions, or delete all variables at the very end of your script.
I'm sorry, but if the emperor is not wearing any clothes, I'll tell him. You are doing the metophorical equivalent ot walking around naked in Times Square. At some point, someone has to tell you. If you think it is rude for being told you are doing something foolish, then too bad.
The fact is, I was never directly insulting to you, nor was I rude in any way. Personally, I suggest that you learn not to shoot the messenger.
Stephen23
on 13 Mar 2020
@Koustubh Shirke: using a function is the easy solution.
Koustubh Shirke
on 13 Mar 2020
Categories
Find more on Programming 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!