Can matlab read data from a file link? - matlab

Question says it all: in a Windows OS, is there a way to make Matlab's csvread or importdata recognize that it needs to follow myfile.csv.lnk to the source file?

Matlab can't process windows shortcut style symbolic links, but it has no problem with ntfs symlinks which were added around Vista and are transparent to applications. I've tested both the symbolic and hard link variants of these and both work fine through Matlab.
You make them using the mklink command, similar to this
mklink test.lnk test.txt

Related

Installing add-ons without display

There are more and more packages on Matlab Central that are shared in the form of add-ons or custom toolboxes (extension .mltbx).
I'm using such toolboxes and when on my desktop I can simply install them by clicking on them. However my code is eventually deployed on a cluster, where none of the nodes has these toolboxes installed and none of the Matlab instance is run with display.
How can I install add-ons programmatically?
Poking around MATLAB's subroutines I couldn't figure out an obvious way to handle this programmatically without at least some user input.
That being said, the *.mltbx package is really just a *.zip file, which we can access directly inside MATLAB. To illustrate this, I've created a quick toolbox using my code prototyping folder, testcode-matlab.mltbx.
If you extract the contents of this file using unzip: unzip('testcode-matlab.mltbx', 'temp'); you should be left with something like the following:
If we examine the contents of fsroot, we see that it's the folder of data packaged into the toolbox:
So we can take this folder, move it to where we want using something like copyfile, and then add it to the MATLAB path using addpath:
copyfile('.\temp\fsroot', '.\mytoolboxes\testtoolbox');
addpath('.\mytoolboxes\testtoolbox');
As of R2016a, there is a MATLAB API to install them:
matlab.addons.toolbox.installToolbox('mytoolbox.mltbx')

Manually Adding Toolbox to Matlab R2013b

I am working with OS X version 10.9.4 and using Matlab R2013b. I have recently downloaded a toolbox file and it saved as a folder on my desktop. It contains a bunch of .m files, which I'm not really sure how to add into my Matlab. I've read online and watched a few tutorials that all mention that I need to set the path to Matlab, but I can't seem to get it to work for me. I'm very new to Matlab and have been trying to figure this out for a couple of days, so my apologies if this is a very simple question to be asking.
There are a couple of ways of doing this. When a function is called in Matlab, it will look in all the directories contained within the path to find it. You can bring up the path by typing in the command "path".
Presumably, you want to add a new location for Matlab to look. This can be done via the addpath command. Addpath accepts both relative and absolute addresses. For example the command
addpath('C:\My_Matlab_Functions')
will enable you to access functions & files within the folder My_Matlab_Functions.
Relative directories are taken relative to the file which calls addpath. For example if I am running a function within C:\users\user_name\My_Documents\Matlab, calling
addpath('Tools')
will enable you to access all of the files within C:\users\user_name\My_Documents\Matlab\Tools. You can also go up directories via '..'. For example, if I am running a function within C:\users\user_name\My_Documents\Matlab\Project1, the command
addpath('..\Tools')
Accesses the same tools folder as before.
I have tried these examples on Windows, but I presume they work the same on a Mac. Hope this helps.
Alternatively, you may be able to add your file(s) directly into Matlab's built in toolbox. I don't know whether Matlab automatically searches for new folders here, but it may be worth a shot.

How to run MATLAB's code from Notepad++

I read this previous question What alternatives are there to the MATLAB Editor? and I am interesting in using another editor so I can also compile my codes with MATALB.
I did what the mentioned link suggested but I cannot see the difference. I went to Preferences Editor/Debbuger and I changed the editor to Notepad++ and nothing happened.
How can I use Notepad++ to compile and run MATALB codes?
P.S. I looked for "run matlab with notpad++" on google but did not find anything interesting.
Also my previous question is related (Can I use MATLAB editor without running MATLAB?).
I answered this a bit more thoroughly here: Running a MATLAB script from Notepad++
Use NppExec add-on and press F6, copy paste the following and save the script:
NPP_SAVE
set local MATPATH=C:\Program Files\MATLAB\R2015a\bin\matlab.exe
cd "$(CURRENT_DIRECTORY)"
"$(MATPATH)" -nodisplay -nosplash -nodesktop -r "try,
run('$(CURRENT_DIRECTOR)$(FILE_NAME)'), catch me, fprintf('%s /
%s\n',me.identifier,me.message), end"
When you mean run matlab code, if you just want to edit it and save and then run from MATLAB terminal, then you can use it just regularly as well. Save in notepad, run on MATLAB.
The problem arises when you want MATLAB editor features like debugger, and execute a block of code within %%. You cannot do all of it. You can set breakpoints, How to debug matlab code without gui
I think you wont get the other features of MATLAB editor if you use an external editor.

Matlab : open OS explorer window only if not already open

I'm opening a folder in Windows explorer from within matlab with the following line :
system('explorer.exe /select,./my_folder/my_file.tif');
It works well, even with the relative path for Matlab "current folder" with "./". Note that it also selects the specified file, which is what I want.
However, I would like to open this window only if the same path isn't already open. Right now, I get several copies of the same window and it's annoying. Do you know any way to do this ?
Thanks,
Ghislain
(Windows 8, Matlab R2011b 64bits)
Disclaimer
This is a partial answer. I don't know how to go on from here, but maybe it helps anyways. Your question is quite interesting to me, and it would make data-analysis a lot easier if changing between interfaces (Matlab/Explorer) were easier!
Some History
DDE is an ancient technology (16-bit Windows, yeah!) that enables Windows applications to talk to each other. DDE has been deperecated from Windows XP on, but it simply refuses to die.
One reason for DDE's longevity is that Windows Explorer still uses DDE a lot. For example, when you double-click a file, the Explorer sends a DDE command to Excel, telling it to open that file in the current Excel window.
How DDE might help you
Matlab's DDE support is officially deprecated. Maybe it would have disappeared completely, were it not for the fact that Explorer talks to Matlab via DDE messages!
You can reverse this process by telling initiating a DDE channel to the application "folders" about the topic "appproperties":
channel = ddeinit('folders', 'appproperties')
The "folders" application appears to be a synonym for "progman", the good ol' Windows 3 program manager. You can tell Explorer ("folders") to view a folder by executing
ddeexec(channel, '[ViewFolder("%l", c:\windows, 5)]')
If Explorer already points to that folder, no new window is opened. Unfortunately, I cannot tell you much more about that command. I don't know what that %l is doing there, or the 5 for that matter. The only thing I know is that ViewFolder can be replaced by ExploreFolder, in which case you always open a new window, and that window always shows the folder tree structure on the left pane.
More Information
The most important DDE-related functions are ddeinit, ddeexec, and ddeterm. Their documentation is buried inside the .m files of those functions. You can view the .m files by simply executing
edit ddeinit
Yair Altman has some more info on Matlab's DDE capabilities. What DDE commands are understdood by Explorer evades me. I assembled my example from what I found here.

Syntax Highlighting While Running MATLAB via Terminal?

I really dislike the MATLAB GUI, thus, I followed some instructions online to open MATLAB via Terminal using matlab -nodesktop. It works. However, I lack the conveniences of syntax highlighting; the sorts that exists in vim, for example.
I am interested in knowing if this is possible.
Try this FileExchange submissions:
Highlighting Matlab files in Vim
Editing Matlab files in Vim
There's Matlab mode for emacs, and also a built-in octave mode which will serve for syntax highlighting.
You can use edit yourfile.m in the terminal to open the matlab editor. This will open the editor without the entire matlab gui. Not sure why you'd want to do this though...