KRIGOLSON TEACHING
  • NEUROSCIENCE
    • NEUROSCIENCE 100 >
      • NEURO 100 INTRODUCTION
      • NEURO 101 ADVANCED
      • NEURO 102 AGING
      • NEURO 103 MEMORY
      • NEURO 104 DECISION MAKING
      • NEURO 105 LEARNING
      • Research Statistics
    • NRSC 500B / MEDS 470
  • Kinesiology
    • EPHE 245
    • EPHE 357
  • STATISTICS
    • BIOMEDICAL STATISTICS
    • MULTIVARIATE STATISTICS >
      • MULTIPLE REGRESSION
    • RESOURCES
    • R TIPS
  • MATLAB
    • THE BASICS >
      • Hello World
      • BASIC MATHEMATICS
      • VARIABLES
      • Matrices
      • Writing Scripts
      • PATHS AND DIRECTORIES
      • USER INPUT
      • FOR LOOPS
      • WHILE LOOPS
      • IF STATEMENTS
      • RANDOM NUMBERS
    • STATISTICS >
      • LOADING DATA
      • DESCRIPTIVE STATISTICS
      • MAKING FUNCTIONS
      • BAR GRAPHS
      • LINE GRAPHS
      • TTESTS
    • EXPERIMENTS: THE BASICS >
      • DRAWING A CIRCLE
      • DRAWING MULTIPLE OBJECTS
      • DRAWING TEXT
      • DRAWING AN IMAGE
      • PLAYING A TONE
      • KEYBOARD INPUT
      • BUILDING A TRIAL
      • BUILDING TRIALS
      • NESTED LOOPS
      • RIGHT OR WRONG
      • SAVING DATA
    • EXPERIMENTS: ADVANCED >
      • STROOP
      • N BACK
      • Oddball
      • Animation
      • VIDEO
    • EEG and ERP Analysis >
      • ERP Analysis
      • FFT Analysis
      • Wavelet Analysis
  • Directed Studies
    • Advanced Topics in Motor Control A
    • Advanced Topics in Motor Control B
    • An Introduction to EEG
    • Advanced EEG and ERP Methods
    • Neural Correlates of Human Reward Processing
    • Independent Research Project
  • RESOURCES
    • EXCEL
    • HOW TO READ A RESEARCH PAPER
    • HOW TO WRITE A RESEARCH PAPER
  • Workshops
    • Iowa State EEG Workshop 2018
  • Python
    • The Basics >
      • Setting Up Python
      • Hello, world!
      • Basic Math & Using Import
      • Variables
      • Matrices
      • Scripts
      • User Input
      • For Loops

PATHS AND DIRECTORIES

​So, we have just written our first program. Where was it saved? If you look at the command window you will see the default MATLAB directory (underlined in red) and a list of the folders and files in the directory (circled in red).
Picture
MATLAB typically creates a folder (MATLAB) in your documents folder to store m-files and related directories. My directory already has some other folders in it. Note, Psychtoolbox does not install here automatically but you can put it here if you wish.

Let's create a folder for the programs we make in this tutorial. Right click in the Current Folder window and create a new folder called "Tutorial".

Picture
Picture
You will notice that the folder is washed out a bit. This is because it is not in the MATLAB path. What is the path? The path is where MATLAB looks for m-files. You have to physically add new folders to the MATLAB path. Otherwise MATLAB cannot "see" the m-files in them. Click on "Set Path". You should see the following screens.
Picture
Picture
Click on Add Folder. Select Tutorial and click on Open.
Picture
This will take you back to the previous screen, but you will see Tutorial at the top of the MATLAB path.
Picture
Click on Save then Close and you will have added Tutorial to the MATLAB path.
Picture
You will notice that Tutorial is no longer washed out but is in bold. This means it is in the path. Also, because we saved the path it will stay in the MATLAB path until you remove it. So, when you open MATLAB again you will not need to add it. Drag my_program.m into Tutorial. Double click on Tutorial. You will note that the Current Folder view is changed so all you see is my_program.m. You will also note that the Working Directory is changed. You can change the directory easily by using the cd command in the Command Window.

cd('~/Desktop')

This command would set the Desktop as the Working Directory. If you try this command out, make sure you set the Working Directory back to Tutorial after. Note, this is in OSX format. This differs slightly on a PC. I am sure you can figure it out by looking at the Working Directory bar.

IMPORTANT. Paths in MATLAB can be dangerous! If you have multiple programs with the same name MATLAB will run the one in the current Working Directory or the first instance of the program it finds if it is not in the Working Directory. As such, try to ALWAYS use unique filenames or be very careful about what is in the path. Also, it is a good idea to use the help command to see if a filename is taken. If you clear all and then try help angle you will see that it actually is already a MATLAB function. To make my_program.m safe, lets make a few changes. Update your code to:


clc;                                        
clear all;                                  
close all;                                  

the_angle = atand(6/4);                         
the_hypotenuse = 6/sind(the_angle);                 
disp(['The angle is: ' num2str(the_angle)]);
​ 

This will ensure that we are not using an existing MATLAB function as a variable name. Save or run this code and move onto the next tutorial!
  • NEUROSCIENCE
    • NEUROSCIENCE 100 >
      • NEURO 100 INTRODUCTION
      • NEURO 101 ADVANCED
      • NEURO 102 AGING
      • NEURO 103 MEMORY
      • NEURO 104 DECISION MAKING
      • NEURO 105 LEARNING
      • Research Statistics
    • NRSC 500B / MEDS 470
  • Kinesiology
    • EPHE 245
    • EPHE 357
  • STATISTICS
    • BIOMEDICAL STATISTICS
    • MULTIVARIATE STATISTICS >
      • MULTIPLE REGRESSION
    • RESOURCES
    • R TIPS
  • MATLAB
    • THE BASICS >
      • Hello World
      • BASIC MATHEMATICS
      • VARIABLES
      • Matrices
      • Writing Scripts
      • PATHS AND DIRECTORIES
      • USER INPUT
      • FOR LOOPS
      • WHILE LOOPS
      • IF STATEMENTS
      • RANDOM NUMBERS
    • STATISTICS >
      • LOADING DATA
      • DESCRIPTIVE STATISTICS
      • MAKING FUNCTIONS
      • BAR GRAPHS
      • LINE GRAPHS
      • TTESTS
    • EXPERIMENTS: THE BASICS >
      • DRAWING A CIRCLE
      • DRAWING MULTIPLE OBJECTS
      • DRAWING TEXT
      • DRAWING AN IMAGE
      • PLAYING A TONE
      • KEYBOARD INPUT
      • BUILDING A TRIAL
      • BUILDING TRIALS
      • NESTED LOOPS
      • RIGHT OR WRONG
      • SAVING DATA
    • EXPERIMENTS: ADVANCED >
      • STROOP
      • N BACK
      • Oddball
      • Animation
      • VIDEO
    • EEG and ERP Analysis >
      • ERP Analysis
      • FFT Analysis
      • Wavelet Analysis
  • Directed Studies
    • Advanced Topics in Motor Control A
    • Advanced Topics in Motor Control B
    • An Introduction to EEG
    • Advanced EEG and ERP Methods
    • Neural Correlates of Human Reward Processing
    • Independent Research Project
  • RESOURCES
    • EXCEL
    • HOW TO READ A RESEARCH PAPER
    • HOW TO WRITE A RESEARCH PAPER
  • Workshops
    • Iowa State EEG Workshop 2018
  • Python
    • The Basics >
      • Setting Up Python
      • Hello, world!
      • Basic Math & Using Import
      • Variables
      • Matrices
      • Scripts
      • User Input
      • For Loops