Why does file have to be saved prior to running? - matlab

In MATLAB, why does the file have to be saved prior to running ?
I often try quick snippets of code, which I could also easily run also on the Command Window line by line. So, why when I run them through the editor, I have to save them first ?
Can this behaviour be changed, maybe ?

You can use cell mode in the editor placing %% before your code. See also Cell menu in the editor. Once you create cells, you can run them one by one pressing Ctrl-Enter. You don't need to save the file. However you cannot use editor's debugging features (breakpoints, etc).
Video tutorial

my guess would be that when you run your program, the matlab interpreter run it from the disk and not from the IDE buffer. so if you don't save the file it wouldn't run the correct code.

Related

MATLAB Simulink Model Configuration Parameters: Empty Window

I am currently working with Simulink and out of the sudden, I am unable to change the Model Configuration Parameters.
Whether I try to open the window via RightClick->Model Configuration Parameters or via Ctrl+E, in both cases, a blank white window opens.
This problem persists after a reboot and opening/closing MATLAB. Furthermore, it is the case for any model (whether old, new, untouched, example...) on my computer. Yesterday I searched for 45min for possible solutions but could not find any.
Is there some graphics cache or can you think of another way, how I could get the dialog back? A photo is attached:
Screenshot: Configuration Parameters window stays blank
Thanks a lot in advance!
This problem happens in Academic version on Simulink. I have not seen it in Original software.
A solution for your problem can be :
1) clear cache of Simulink by typeing the following command in command window :
rehash toolboxcache
2) reset menu and toolbar of Simulink by the following command :
sl_refresh_customizations
Then close MATLAB by exit command.

Breakpoint in section of Matlab

I have written a MATLAB code defined in different sections. After running the first section of my code I would like to be able to debug subsequent sections using breakpoints. For some reason, however, when I add a breakpoint and use the "Run Section" command the debug mode is not triggered. It appears that I'm unable to run the beginning of the program and then use a breakpoint and the "Run Section" command. Does anyone know how to do this? I'm doing this to save time since the beginning of my program takes a long time to run. Thanks.
There are a couple of work-arounds I can think of which might help you.
First, when you get to your breakpoint, save the entire workspace to a .mat file. Then comment out all the code up to this point and add a line to load your .mat file. You can now get to the point in your code you are debugging quickly.
Another way to do it would be to put all the code past your breakpoint in a separate script. Then when you hit the breakpoint, you can set more breakpoints in the second script and call it from the command window as many times as you need.

Difference between position of elements of GUI before and after open it in GUIDE in MATLAB

I'm designing a GUI with GUIDE. When I open a window in GUIDE and after that run it, position of elements like panels,radio buttons and etc are difference with when I run MATLAB and directly run a GUI from .m file. It is a confusing problem because the real positions are that I'm running from .m file.
All elements of the window are nearly 1 cm to the right compared to when running it directly and I have a little vertical difference between these two. I should design a window and after that close MATLAB and run it directly to see the real positions! If I directly open it from .m file after using GUIDE, there isn't any difference with running from GUIDE and run from .m file. I have to restart MATLAB to see the difference.
What is your idea about this problem? How can I solve it?
Idea 1
This is more of a workaround rather than a solution:
What you could do, after positioning all elements in GUIDE, is to export the figure to an .m file (you don't actually need the .fig in order to have an interactive figure) using the menubar option File > Export ... in GUIDE.
This way you'll get an .m file with all the elements' positions hardcoded. If you change the position values from that file, there is absolutely no chance that they'll appear someplace else.
Idea 2
Try setting the Resize behavior of the GUI to Non-resizable. This is accessible from the GUIDE menu by Tools > GUI Options...

How to run the code without the GUI

I have a rather long perltk code in my hand and I would like to run the simulation in a batch mode (without using the GUI). e.g. I would like to run it with script like "myprog.pl -b" in stead of setting all the parameters in the GUI and click buttons.
My current method is using a separated XML file for config and the function "after" which means the GUI will pop-out and start the simulation then exit after sometime. It is now working, but I have a question: is there a better way solve this problem? Is that possible to have the GUI shown in the background (so we wont see it) in stead of pop-out?
Change the program so it is accessible from both a graphical and command-line interface. Factor out its real functionality into subroutines.
Run the program in an xvfb so that no window is shown on the main display.
Configure the window manager to always start instances of this program minimised and/or with a 0x0 size.

My output on Emacs is showing the whole code not the output

I put my code in and compile it but then it shows up in word pad with no output just the whole code. is something wrong with Emacs?
It sounds like compile mode is misconfigured, or you're putting in the wrong compile command when it prompts you. You're on windows, where attempting to execute a file that isn't itself executable will instead launch the program registered to view or edit that type of file. You must have wordpad configured as the default viewer for the files you're editing.