Matlab and simulink stateflow chart error - matlab

I have been trying to use "stateflow chart" block for hours. However, I keep getting this error:
The current directory is c:\program files\matlab13\bin, which is reserved for MATLAB files. Please change your current directory to a writable directory preferably outside of MATLAB installation area.
What I have done:
moved the model from bin to my E:\drive but nothing is going good.

But did you actually change directories. For example typing in the command window:
cd('E:\drive');
You could also change your current directory by changing the current folder from the second menu bar at the top of the Matlab window. If you do it either way, you should be no longer in the Matlab installation area and the first error message should not appear. If things are still not working out, you will have to share the new error message with us.

Related

Why is my workspace window empty (while I can see my variables with "whos")?

So I am having this problem for a few days now.
I am using Matlab R2017b on Mac, and it worked perfectly up untill a few days ago when I ran a code (not for the first time) and my variables did not appear in the workspace window. However I can see them all when using the command "whos".
I was running very simple scripts to create graphs and perform stats.
I have no idea if it is related, I wouldn't think so but just in case, it happened when I ran the code and also got that warning:
"Cleaning up unclosed ZipFile for archive
/Users/.../CD_EBCC_data.xlsx"
I've rebooted the computer but no changes.
Thanks in advance for your help! Let me know if any extra info could be of help.
EDIT:
Here a screenshot:
on the left are all my variables as visualized with "whos", on the right you can see the empty workspace.
If I type "a=1" in the command window, there is no variable a created in the workspace but if I type whos I can see it is actually there. It is just that I cannot see it in the workspace window. If I type the name of an existing variable, it is displayed normaly in the command window. Hope that is clearer.

Does Matlab have "project files"?

For example: Rstudio uses so called projects - text files ending with .Rproj. When you click on a project file, it opens up Rstudio and sets working dir to where the project file is. Optionally, it executes any code written it. However, it does not open itself (i.e., it does not show up in the script editor).
Is there something like that in Matlab? If not, how to emulate it?
Currently I use to make an .m file with cd, addpath calls etc. But when I click in the file browser:
it just opens Matlab and shows up in the script editor without running
opening Matlab is what I want, but showing up in the script editor is actually redundant; I only need to run it (and use the results in my Matlab desktop session)
(What I want to avoid is having to open the script file, run it manually and then having to close it again. It is annoying!)- edited
Matlab does not have "project files" (as far as I know).
However, I think you can easily emulate what you want.
Let's suppose you have your code in a folder C:\MyProject:
1) Create a new m-file C:\MyProject\MyProject.m with all your initialization code (cd, addpath calls, global variables, whatever you need).
Here's a simple example for demonstration purposes:
disp('Replace this with your initialization code');
2) Create a batch-file C:\MyProject\MyProject.bat as follows:
MATLAB -r "run MyProject"
Now, by double-clicking the batch-file you will:
open the complete Matlab environment
execute the script MyProject.m (without loading it in the script editor)
For this purpose, MATLAB offers startup.m files (online documentation).
You have to put all your initialization code in a file called startup.m, which needs to be located within the MATLAB search path (i.e. within your project folder). The script will be executed every time you open MATLAB by double-clicking a arbitrary m-file from your project folder.

waitbar matlab before start a standalone script

I did a standalone application in Matlab and it works. The only problem is that when I launch the application, it takes time before start asking to the user some file (it is the first think the program has to do). The user does not understand if the program is working or not, since no message neither symbol of working progress appear on the screen.
My idea is to show a waitbar until the window asking the file to user appears.
How can I do this? is it possible to use the waitbar outside a loop?
The script starts as follow:
close all
clear all
[filename,pathname] = uigetfile({'*.xlsx'},'Opening File','C:\');
I don't know why, it takes time before open the window for choosing the file.
The time between launch and file selection input appearing is most likely due to the time it takes to load the MCR. You could add a splash screen to your compilation.
If the end user is running from a command line wrap your exe in a system/shell which writes to the command window that the application is starting.
Your issue is most likely the use of clear all. This makes MATLAB remove all variables (in scope, global and persistent), and compiled scripts from memory, forcing it to recompile and load everything again.
If your purpose is to clear all variables in the current scope, you should be able to increase the initial speed of your script by only running clear instead.
Even faster speed can be achieved if you specify which variables to clear using clear var1 var2 ...

Matlab clc command

I was checking the original 'clc.m' file in MATLAB. Apparently the function is written as a p-code and you just see the description which is placed in:
..\MATLAB\R2013a\toolbox\matlab\iofun\clc.m
How can I take a look at the original code?; however this is not the main question, it is just for fun.
The main point is I am looking for a way to reverse the clc process, after you clean the screen. Is there any way to reverse the clc process. The same question goes for clear all as well.
Try using home instead of clc. Whereas clc removes all text from the Command Window and moves the cursor to the top left giving you a blank window, home just moves the cursor to the top left and gives a you a blank window - but the text is still there, and you can scroll up to see it. I use home all the time rather than clc.
In either case, the text remains in the Command History window, and can be retrieved in the Command Window using the Up/Down arrows.
The reason you can't see the code behind clc is not that it's p-coded, it's that it's a built-in function (i.e. not implemented in the MATLAB language). The same is true for clear, and also many math functions such as svd, eig etc. There's no way to modify them to change what they do (such as reversing the process).
Edit: You might also like to look into the diary function, which keeps a log of all the input and output at the command window in a specified file. I have the following lines in my startup.m file (type doc startup if you don't know how to use MATLAB startup files):
diaryFolder = 'C:\diaries';
diaryFileName = ['diary', datestr(now, 'yyyymmdd'), '.txt'];
diary(fullfile(diaryFolder, diaryFileName))
So whenever I start MATLAB, it's automatically capturing all command window input and output to a diary file that's named by the date - If I start MATLAB multiple times a day, it just appends to the same file. I can clc or home whenever convenient, and there's always a record kept of everything that I can search through if necessary.
I don't believe there would be anyway to undo the clc process. That said, it is possible to still view the command history, so that might get you somewhere.
Once you clear the data, I believe it's gone forever. I highly doubt that data is stored in memory somewhere. I know that after a certain number of lines, the history is deleted. So your best bet is to start figuring out how large that buffer is and proceed from there to see if you can find anything interesting.

Where is startup.m supposed to be?

I've been chasing the answer to this question in the MATLAB documentation for a long time...
For example, at the bottom of
http://www.mathworks.com/help/matlab/matlab_env/changing-the-startup-folder.html
it says
Use the startup.m file to specify the startup folder...
...which is plainly absurd, since elsewhere the documentation says that startup.m is to be found in the so-called "startup folder". So therefore there's no way for this file to specify where this folder should be.
Etc., etc., etc. This sort of circularity pervades everything I've found in the docs on startup.m.
What I want to know is: can I or can't I customize the location of the "startup folder" in a way that is persistent, and if so, where is this persistent information stored?
The best method, I find, is this. Let's say you want MATLAB to start up in mystartupdir, and you've placed startup.m in that directory.
On Windows, make a shortcut icon to MATLAB, then right-click on it and select Properties. Edit the field Start In. Now, use this icon whenever you want to start MATLAB.
On other platforms, you can run MATLAB with the -sd flag to specify the startup directory:
matlab -sd mystartupdir
If you don't specify a startup directory, MATLAB will use the default specified by the userpath command. You can place your startup.m file there.
According to this page in the docs, you should create your own startup.m in the "startup directory" which, if you follow the link, leads to this page explaining the definition of "startup directory" in this context.
You can retrieve this "startup directory" with the userpath function which returns, on my system:
>> userpath
ans =
C:\Users\MYUSERNAME\Documents\MATLAB;
Personally, I just set the "Start In" in the shortcut to whatever I want - but obviously this won't work if you're not on Windows; if you're not on Windows or prefer not to rely on the shortcut you should create a startup.m with a call to cd in whatever directory userpath returns.
The docs also say you can modify the userpath function, if you so desire, or the matlabrc.m file in matlabroot/toolbox/local (but you can only do the latter if you're a MathWorks engineer or a system administrator, otherwise MathWorks will rain fiery hell down on you from above, or something...).
On Mac OS X, you may put your startup.m file in /matlabrootfolder/toolbox/local/. For example, this path might look like the following for Matlab 2012: /Applications/MATLAB_R2012a.app/toolbox/local/.
To prevent the file from being removed after upgrading Matlab, you may use a symlink to the file. If your startup file is stored at $HOME/myDir/startup.m, for example (in Bash):
cd /Applications/MATLAB_R2012a.app/toolbox/local/
ln -s ~/myDir/startup.m .
Reference: http://www.mathworks.com/help/matlab/matlab_env/startup-options.html
This is meant as a pointer for Lx users (as confused as I was at first...). I work on Debian based boxes, but the same should apply to the CentOS system lineup, etc.
Check that after install you do have the directory/ies: ~/.matlab/<yr_release(s)>
Note that you may have several releases there as is my case. matlab actually permits that.
Create ~/.matlab/startup.m Incidentally I also created my directory Workspace there. That's completely optional
In your Matlab window's Home tab find the menu iten/icon Set Path, click on it and add a "matlab search path" with the button Add folder top left. Add ~/.matlab as a new search path. Change should take effect immediately.
Restart Matlab to check that the content of ~/.matlab/startup.m is correctly taken into account at launch time.
I hate GUIs... I thought you might want to know ;-) HTH.
As read in http://fr.mathworks.com/help/matlab/matlab_env/matlab-startup-folder.html#buj_13n :
Changing the Startup Folder
Starting in R2014b, you can change the startup folder using the
General Preferences panel. On the Home tab, in the Environment
section, click Preferences. Select MATLAB > General. Choose an option
for the Initial working folder.
By default, the initial working folder is set to Location based on
MATLAB startup rules.
I wish it did not involve the graphical desktop interface, though. By looking closely in the file matlab.setting, which under Linux should lie in ~/.matlab/<your_release>/, you can find the lines
<key name="UserPath">
<string>
<value><![CDATA[<some_directory>]]></value>
</string>
</key>
where you can certainly specify manually the startup directory.
For me (I'm using Linux) it worked to put the "startup.m" to the home directory. Apparently, the home directory is by default on the matlab path. Strangely, it also worked when I put the "startup.m" into a newly created "matlab" (must be all lower-case) folder in the home directory. Let me know whether it also works on your system.