[absolute beginner] what is the difference between addpath and directories?
39 次查看(过去 30 天)
显示 更早的评论
Dani
2023-10-10
I have no programming experience and need to learn quickly so please be gentle on me.
I was told to think of directories as like a file cabinet in a computer. I understand that, but what does it mean then when we "addpath" prior to that? The code I am learning from has a section of code for adding paths. I am trying to get this visualized in my head. what comes after my addpath is stuff like 'C:\Users\JohnSmith\Downloads...."
is the addpath another type of file cabinet? is it where info gets put into? or taken from?
Thanks...
15 个评论
dpb
2023-10-10
"paths" are the specific folders in the cabinet drawer analogy; addpath is a function that allows you to add another folder path to the list MATLAB uses in where it does look for data and function ("m") files. <Read all about it here>
Dani
2023-10-10
How does it relate to when we set up directories after? if the directories are more of the outer creature, why does the code use addpaths first?
Thank you for your help.
dpb
2023-10-10
Because apparently those locations were not in the original path and the author of the code was taking the lazy and not recommended way out in adding folders to the path in which the data resided. Doing it this way means one can use filenames that don't have a specific path specified (a "fully qualified" filename), but it has the side effect of modifying the path and if run multiple times could end up duplicating the same paths/folders over and over unless it has code to verify whether the path(s) in question are already in the matlabpath variable. It gets messy quickly to do this.
The preferred and better way is to not actually modify the path but use fully qualified filenames, addressing the files in their locations/folders via constructing filenames with fullfile. This keeps the path itself at the minimum and doesn't muck it up for a specific use that then needs cleaning up when the desired locations change. And, it would be particularly bad to do something of this sort with code provided to someone else and thereby messing with their environment and potentially breaking something there. "That's just plain rude!" to do something like that.
We would have to see the actual code itself to be able to fully appreciate what is being done and, perhaps, suggest "more better" ways.
John D'Errico
2023-10-10
Your computer has a file structure. Think of it as a tree, where the tree can then branch to deeper and deeper levels. I suppose you can think of this in terms of roots of the tree, so branching downwards. Every location in that structure can have files inside it, or it can have links you can follow down to the deeper levels that lie below it. Each of these locations is called a directory. And all of this is completely independent of MATLAB, just the file system on your computer.
MATLAB does not automatically see every branch of that tree, as the file sytem on any normal computer will be huge, with a huge number of files in them. Instead, you need to tell MATLAB where to look for m-files. Thins like this:
'C:\Users\JohnSmith\Downloads..."
are the names, essentially the locations of each of those directories on your computer. So if you went to
'C:'
you probably won't see any files stored there. But just some directory links you can follow down. One of them will be:
'C:\Users'
Inside that directory, you will then see a directory named 'JohnSmith', and you can keep on drilling down. At some point, some of these deeper directories will begin to store actual files, though probably not MATLAB files, at least not yet.
Again, all of this is purely the file system on your computer. What MATLAB needs are the names of each directory where it will be asked to look for m-files. I would suggest that you create your own directory, where your personal m-files will be stored.
The search path on MATLAB is the list of directories where it has permission from you to look for m-files. Of course, that search path will include all of the directories provided with MATLAB itself, because most of MATLAB is written in MATLAB, just sets of M-files, though for the code which must run most quickly, it will be compiled code.
How do you tell MATLAB where to look for your own m-files you will create? That is done using addpath, or perhaps pathtool if you prefer.
Dani
2023-10-10
I had no idea. See, I feel I am grasping at straws in the dark teaching myself based on someone elses code... In the code, addpath is done first (EEGLAB) and then setting up directories.
Dani
2023-10-10
@John D'Errico that is a very helpful analogy. In the code I am working with, the addpath is done first and then setting up directories.
John D'Errico
2023-10-10
But we don't know what the code is doing, and why. Why new directories are being established programatically is not something we know, because we cannot see your code. We cannot look inside your computer.
ADDPATH tells MAT:AB where to look for m-files. It will look for m-files only there, along with the current directory where MATLAB is set to look. You control the current directory using the function CD. As well, you can learn the current directory using the PWD function.
dpb
2023-10-10
编辑:dpb
2023-10-11
"... In the code, addpath is done first (EEGLAB) and then setting up directories. "
Are you looking at the EEGLAB code itself or some other code using EEGLAB?
EEGLAB is a humongous and extremely complex piece of code/standalone application; it is definitely not somewhere to try to start learning coding from no knowledge base at all.
Dani
2023-10-10
I have to though. I have no background in it at all but it’s kind of my due to pay if I want to get into the PhD program. I have to get into the PhD for several reasons… the failure is not an option but I’m also struggling… I wish I had a tutor but I can’t find anyone.
Dani
2023-10-10
To answer your question I have to teach myself what the labs pipeline is doing and the goal is I can run it myself and code myself. It’s for pre processing eeg data using the Eeglab.
dpb
2023-10-11
编辑:dpb
2023-10-11
Preprocessing for then importing into EEGLAB could be one thing; munging with EEGLAB itself would be "a whole 'nother kettle of fish". I poked at it some in trying to help another poster a while back analyze some data with EEGLAB. It took quite a long time just to figure out its convention for loading data despite having used MATLAB for some 30+ years.
I have no idea what your committee might think is a prerequisite for acceptance into the program, of course, and I'm not going to pretend I can tell you the best approach, but I'm pretty confident you'll not get very far very fast in learning fundamentals of coding and MATLAB enough to even begin to understand EEGLAB by trying to read its code as the diving-in point.
dpb
2023-10-11
编辑:dpb
2023-10-11
"...In the code, addpath is done first (EEGLAB) and then setting up directories. "
As noted above EEGLAB is a (very, very large and complex) application written in MATLAB. Being essentially another shell programming language built around MATLAB for the specific chore of analyzing EEG data, it loads itself and adds the set of subdirectories/folders it uses for all its own code on top of the basic MATLAB code folders and toolboxes the particular installation has.
It does this in code rather than forcibly redefining the user's MATLAB installation permanently so that when it terminates the path is back to what it was before.
There is quite a lot of tutorial information at the EEGLAB wiki site; one of the unusual features it seems to me for as well developed a product as it is is that it doesn't really have an install setup to add it as a MATLAB application addon; it seems to have somewhat the same mentality as much of MATLAB historically; one is expected to know basic programming fundamentals and write code and/or do the other housekeeping details needed. Hence, the instructions for <Adding EEGLAB to MATLAB path> so you don't have to navigate manually to the location you downloaded to and run the toplevel m file from there. You would think that would be a routine setup/installation with the product, but it isn't....
But, all the addpath stuff (and it has its own wrapper myaddpath that it uses) is simply getting things set up so it knows where the user put it when downloaded and uncompressed it so can find all its own m files, nothing more. It has to do that since it doesn't come with an install script to put it in some known location; the user can download it and put it anywhere so chooses so it has to find out where that is and then set the path as needed from that base location.
It's really just background maintenance that has no real bearing on using it for analyzing data; you would do better to focus on how to get data into and out of it to do analyses and then, perhaps, depending upon just what you would be expected to be able to do, find some tutorials on writing scripts to automate some of the other analyses that may not be fully implemented.
Steven Lord
2023-10-11
If you haven't already done so, I suggest you go through the free MATLAB Onramp tutorial to quickly learn the essentials of MATLAB. This should give you a basic foundation upon which you can add the skills necessary to work with or work on EEGLAB. Based on what I've seen here on MATLAB Answers that may still take a bit of a climb up a learning curve, but knowing what's in the Onramp will help you start off well.
dpb
2023-10-12
Good luck, I hope have helped some; I'm glad @Steven Lord thought to add the link to the On Ramp course; if you weren't aware of it, particularly. I tend to think folks will start with the "Getting Started" section in the doc without prompting, but should know better... :)
I just was concerned you were heading in a direction that was not going to be at all fruitful towards your end goals and could waste a lot of precious time trying to delve into the bowels of the code itself instead of concentrating on its use first and then some level of familiarity with basic MATLAB operations in order to understand its nomenclature and data structures -- which are just big MATLAB structures with a set of specific naming conventions. I got that far in the previous looking at for the forum I had done, but I have not downloaded and installed EEGLAB and "know nothink!" about EEGs in general, only something about MATLAB that can usually ferret out what is needed.
回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Startup and Shutdown 的更多信息
标签
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!发生错误
由于页面发生更改,无法完成操作。请重新加载页面以查看其更新后的状态。
您也可以从以下列表中选择网站:
如何获得最佳网站性能
选择中国网站(中文或英文)以获得最佳网站性能。其他 MathWorks 国家/地区网站并未针对您所在位置的访问进行优化。
美洲
- América Latina (Español)
- Canada (English)
- United States (English)
欧洲
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
亚太
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)