Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
System Function | Visualizations
Matlab Basics
course content

Conteúdo do Curso

Matlab Basics

Matlab Basics

1. Basic Syntax and Coding with a Text Editor
2. Coding Foundations
3. Learning Through Applications
4. Visualizations
5. Recursion and Matrix Multiplication

book
System Function

Learn how to have Matlab move, rename, and copy files and folders on your computer, as well as retrieve the contents of folder directories. These handy functions can save you a lot of busy work, and in the next section, we'll use them to automate graphing and analyses across an entire directory folders containing data files.

Task

Mess around! Create some dummy files and folders and have Matlab move, rename, and copy them around your computer.

Place 4+ copies of the Excel file from chapter 3 into a folder on your computer. Then:

  • Use the dir function to return a structure of the directory of all the Excel files in this folder;

  • Create a blank cell array;

  • Use a for loop to populate the cell array with single strings containing the entire file location (location + file names) of all the Excel files in the folder.

Fair warning: what you build in this second part will be used in the first chapter of the next section.

The variable you assign to capture the directory returned from dir will have the form of a structure: an array where variables are assigned to each element of the array.

The structure will have just a single-column; therefore, referencing other columns, like (1,2), will trigger an error.

Use the length function to determine how many elements (files) are in the structure.

Indexing the first element of your structure variable, e.g., directory(1,1), will bring up a list of all the variable names stored for each file.

Specific variables are then retrieved by adding a period, followed by the variable name, after this index: e.g., directory(1,1).name.

Use strcat to concatenate the file name (a string) with the folder location you chose (another string), perhaps with an intermittent /, to get a single string with the full file location + name.

Trying with just one Excel file in the folder, and entering code manually in the command window to manipulate the variables into what you want, can help elucidate errors and is easy to do in this case.

Tudo estava claro?

Como podemos melhorá-lo?

Obrigado pelo seu feedback!

Seção 4. Capítulo 5
We're sorry to hear that something went wrong. What happened?
some-alt