Matlab does not open m files. MATLAB file extension

The table below provides useful information about the .matlab file extension. It answers questions such as:

  • What is a file? matlab?
  • What software do I need to open the file. matlab?
  • Like a file. matlab be opened, edited or printed?
  • How to convert. matlab files to a different format?

We hope you find this page a useful and valuable resource!

0 extensions and 1 aliases found in the database

✅ MATLAB Script

Description (in English):
M file is a MATLAB Script. MATLAB is a high-level language and interactive environment that enables you to perform computationally intensive tasks faster than with traditional programming languages ​​such as C, C++, and Fortran.

MIME type: application/matlab-m

Magic number: -

Magic number: -

Sample: -

M aliases:

matlab

Related links:

M related extensions:

Other file types may also use the file extension .matlab.

🔴 Can't open .matlab file?

When you double-click a file to open it, Windows checks the file name extension. If Windows recognizes a filename extension, the file opens in a program that is associated with that filename extension. When Windows does not recognize the file name extension, the following message appears:

Windows can't open this file:

Example.matlab

To open this file, Windows needs to know what program you want to use to open it...

If you don't know how to set up file associations .matlab, check .

🔴 Is it possible to change the file extension?

Changing the file name and file extension is not a good idea. When you change a file extension, you change the way programs on your computer read the file. The problem is that changing the file extension does not change the file format.

If you have any useful information about the file extension .matlab, !

🔴 Rate our MATLAB page

Please help us by rating our page MATLAB in the 5-star rating system below. (1 star bad, 5 stars excellent)

Working from the MatLab command line is difficult if you need to enter a lot of commands and change them frequently. Keeping a diary using the diary command and saving the working environment only makes things a little easier. The most convenient way to execute MatLab commands is to use M-files, in which you can type commands, execute them all at once or in parts, save them in a file and use them in the future. The M-file editor is designed to work with M-files. Using this editor, you can create your own functions and call them, including from the command line.

Expand menu File main MatLab window and in the item New select sub-item M-file. The new file opens in the M-file editor window.

Enter commands in the editor that lead to the construction of two graphs in one graphics window:

x = ;
f = exp(-x);
subplot(1, 2, 1)
plot(x, f)
g = sin(x);
subplot(1, 2, 2)
plot(x, g)

Now save the file called mydemo.m in a subdirectory work main MatLab directory by selecting Save as menu File editor. To run all commands contained in the file, select Run on the menu Debug. A graphic window will appear on the screen Figure No.1, containing graphs of functions. If you decide to plot cosine instead of sine, then simply change the line g = sin(x) in the M-file to g = cos(x) and run all the commands again.

Note 1

If an error is made while typing and MatLab cannot recognize the command, then the commands up to the incorrectly entered one are executed, after which an error message is displayed in the command window.

A very convenient feature provided by the M-file editor is execution of some commands. Close the graphics window Figure No.1. Select using the mouse while holding the left button, or using the arrow keys while holding down the key , the first four commands of the program and execute them from point Evaluate Selection menu Text. Please note that only one graph corresponding to the executed commands was displayed in the graphics window. Remember that to execute some commands you must select them and press . Execute the remaining three program commands and monitor the state of the graphics window. Practice on your own, type some examples from previous labs in the M-file editor and run them.

Individual M-file blocks can be supplied comments, which are skipped when executed, but are convenient when working with an M-file. Comments in MatLab begin with a percent sign and are automatically highlighted in green, for example:

% plotting sin(x) in a separate window

The M-file editor can have multiple files open at the same time. The transition between files is carried out using bookmarks with file names located at the bottom of the editor window.

Opening an existing M-file is done using the item Open menu File working environment, or M-file editor. You can also open the file in the editor using the MatLab edit command from the command line, specifying the file name as an argument, for example:

The edit command without an argument creates a new file.
All examples that appear in this and the following labs are best typed and saved in M-files, supplemented with comments, and executed from the M-file editor. The use of numerical methods and programming in MatLab requires the creation of M-files.

2. Types of M-files

There are two types of M-files in MatLab: program file(Script M-Files) containing a sequence of commands, and file-function(Function M-Files), which describe user-defined functions.

You created the file program (file procedure) when reading the previous subsection. All variables declared in the file program become available in the working environment after its execution. Execute the file program given in subsection 2.1 in the M file editor and type the whos command at the command line to view the contents of the working environment. A description of the variables will appear in the command window:

"Whos
Name Size Bytes Class
f 1x71 568 double array
g 1x71 568 double array
x 1x71 568 double array
Grand total is 213 elements using 1704 bytes

Variables defined in one file program can be used in other file programs and in commands executed from the command line. Execution of commands contained in a file program is carried out in two ways:

  • From the M-file editor as described above.
  • From the command line or another file program, using the name of the M file as the command.

Using the second method is much more convenient, especially if the created file program will be used repeatedly in the future. In fact, the created M-file becomes a command that MatLab understands. Close all graphical windows and type mydemo in the command line, a graphical window appears corresponding to the commands of the mydemo.m program file. After entering the mydemo command, MatLab performs the following actions.

  • Checks whether the command entered is the name of any of the variables defined in the runtime. If a variable is entered, its value is displayed.
  • If the input is not a variable, then MatLab looks for the entered command among the built-in functions. If the command turns out to be a built-in function, then it is executed.

If neither a variable nor a built-in function is entered, then MatLab begins searching for an M-file with the command name and extension m. The search starts with current directory(Current Directory), if the M-file is not found in it, then MatLab looks through the directories installed in search paths(Path). The found M-file is executed in MatLab.

If none of the above actions resulted in success, a message is displayed in the command window, for example:

» mydem
??? Undefined function or variable "mydem".

Typically, M-files are stored in the user's directory. In order for the MatLab system to find them, the paths must be set to indicate the location of the M-files.

Note 2

There are two reasons to store your own M-files outside of the main MatLab directory. First, when you reinstall MatLab, files that are contained in subdirectories of the main MatLab directory may be destroyed. Secondly, when MatLab is launched, all files in the toolbox subdirectory are placed in the computer’s memory in some optimal way so as to increase performance. If you wrote the M-file to this directory, you can use it only after restarting MatLab.

3. Setting paths

In MatLab versions 6 .x the current directory and search paths are determined. Setting these properties is done either using the corresponding dialog boxes or using commands from the command line.

The current directory is determined in the dialog box Current Directory working environment. The window is present in the workspace if the option is selected Current Directory menu View working environment.
The current directory is selected from the list. If it is not in the list, you can add it from the dialog box Browse for Folder called by clicking on the button located to the right of the list. The contents of the current directory are displayed in the file table.

Search paths are defined in the dialog box Set Path path navigator, accessed from the point Set Path menu File working environment.

To add a catalog, click the button Add Folder Browse for Path select the required directory. Adding a directory with all its subdirectories is done by clicking on the button Add with Subfolders. MATLAB search path. The search order corresponds to the location of the paths in this field; the directory whose path is located at the top of the list is searched first. You can change the search order or even remove the path to a directory by selecting the directory in the field MATLAB search path and determine its position using the following buttons:
Move to Top - place at the top of the list;
Move Up - move up one position;
Remove - remove from list;
Move Down - move down one position;
Move to Bottom - place at the bottom of the list.

4. Commands for setting paths.

Steps to set paths in MatLab 6 .x are duplicated by teams. The current directory is set with the cd command, for example cd c:\users\igor. The cd command, issued without an argument, prints the path to the current directory. To set paths, use the path command, called with two arguments:

path (path, "c:\users\igor") - adds the c:\users\igor directory with the lowest search priority;
path ("c:\users\igor",path) - adds the directory c:\users\igor with the highest search priority.

Using the path command without arguments causes a list of search paths to be displayed on the screen. You can remove a path from the list using the rmpath command:

rmpath("c:\users\igor") removes the path to the directory c:\users\igor from the list of paths.

Note 3

Do not delete directory paths unnecessarily, especially those whose purpose you are not sure of. Removal may result in some of the functions defined in MatLab becoming unavailable.

Example. Create in the root directory of the disk D(or any other disk or directory where students are allowed to create their own directories) a directory with your last name, for example, WORK_IVANOV, and write the M-file mydemo.m there under the name mydemo3.m. Set file paths and demonstrate file accessibility from the command line. Provide the results in your laboratory report.

Solution option:

1. In the root directory of the disk D the WORK_IVANOV directory is created.
2. The M-file mydemo.m is written to the WORK_IVANOV directory under the name mydemo3.m.
3. A dialog box opens Set Path menu File MatLab working environment.
4. The button is pressed Add Folder and in the dialog box that appears Browse for Path the WORK_IVANOV directory is selected.
5. Adding a directory with all its subdirectories is done by clicking on the button Add with Subfolders. The path to the added directory appears in the field MATLAB search path.
6. To remember the path, press the key Save dialog box Set Path.
7. The correctness of all actions is checked by typing the mydemo3 command from the command line. A graphics window will appear on the screen.

5. File functions

The file programs discussed above are a sequence of MatLab commands; they do not have input or output arguments. To use numerical methods and when programming your own applications in MatLab, you must be able to create file functions that perform the necessary actions with input arguments and return the result in output arguments. This subsection contains several simple examples to help you understand how to work with file functions. File functions, as well as file procedures, are created in the M-file editor.

5.1. File functions with one input argument

Suppose that in calculations it is often necessary to use the function

It makes sense to write a file function once, and then call it wherever this function needs to be calculated. Open a new file in the M-file editor and type the listing text

function f = myfun(x)
f= exp(-x)*sqrt((x^2+1)/(x^4+0.1));

The word function in the first line specifies that this file contains a function file. The first line is function header, which houses function name and lists of input and output arguments. In the example shown in the listing, the function name is myfun, one input argument is x and one output argument is f. After the title comes function body(in this example it consists of one line), where its value is calculated. It is important that the calculated value is written to f. The semicolon is included to prevent unnecessary information from being displayed on the screen.

Now save the file in your working directory. Please note that selecting an item Save or Save as menu File causes a dialog box to save the file to appear, in the field File name which already contains the name myfun. Don't change it, save the function file in a file with the suggested name.

Now the created function can be used in the same way as the built-in sin, cos and others, for example from the command line:

» y =myfun(1.3)
Y =
0.2600

Own functions can be called from a file program and from another file function.

Warning

The directory containing the function file must be current, or its path must be added to the search path, otherwise MatLab simply will not find the function, or will call another with the same name instead (if it is in searchable directories ).

The file function given in the listing has one significant drawback. Trying to evaluate a function's values ​​from an array results in an error rather than an array of values, as happens when evaluating built-in functions.

» x = ;
» y = myfun(x)
??? Error using ==> ^
Matrix must be square.
Error in ==> C:\MATLABRll\work\myfun.m
On line 2 ==> f = exp(-x)*sqrt((x^2+1)/(x^4+1));

If you have learned how to work with arrays, then eliminating this shortcoming will not be difficult. You just need to use element-wise operations when calculating the value of a function.
Modify the function body as shown in the following listing (remember to save the changes in the myfun.m file).

function f = myfun(x)
f = exp(-x).*sqrt((x.^2+1)./(x.^4+0.1));

Now the argument to the myfun function can be either a number or a vector or matrix of values, for example:

» x = ;
» y = myfun(x)
Y =
0.2600 0.0001

The variable y, into which the result of calling the myfun function is written, automatically becomes a vector of the required size.

Plot the myfun function on a segment from the command line or using a file program:

x = ;
y = myfun(x);
plot(x, y)

MatLab provides another way to work with file functions - using them as arguments to some commands. For example, to plot a graph, use the special fplot function, which replaces the sequence of commands given above. When calling fplot, the name of the function whose graph you want to plot is enclosed in apostrophes, the plotting limits are indicated in a row vector of two elements

fplot("myfun", )

Plot myfun graphs using plot and fplot on the same axes, using hold on. Please note that the graph constructed using fplot more accurately reflects the behavior of the function, since fplot itself selects the argument step, reducing it in areas of rapid change in the displayed function. Provide the results in your laboratory report.

5.2. File functions with multiple input arguments

Writing file functions with multiple input arguments is practically no different from writing with one argument. All input arguments are placed in a list separated by commas. For example, the following listing contains a file function that calculates the length of the radius vector of a point in three-dimensional space
Listing of a file function with several arguments

function r = radius3(x, y, z)
r = sqrt(x.^2 + y.^2 + z.^2);

» R = radius3(1, 1, 1)
R=
1.732

In addition to functions with multiple input arguments, MatLab allows you to create functions that return multiple values, i.e. having multiple output arguments.

5.3. File functions with multiple output arguments

File functions with multiple output arguments are useful when evaluating functions that return multiple values ​​(in mathematics they are called vector functions). Output arguments are appended to the list of output arguments, separated by commas, and the list itself is enclosed in square brackets. A good example is a function that converts a time specified in seconds into hours, minutes, and seconds. This file function is shown in the following listing.

Listing of the function for converting seconds to hours, minutes and seconds

function = hms(sec)
hour = floor(sec/3600);
minute = floor((sec-hour*3600)/60);
second = sec-hour*3600-minute*60;

When calling file functions with multiple output arguments, the result should be written to a vector of appropriate length:

» [N, M, S] = hms(10000)
H=
2
M =
46
S=
40

6. Basics of programming in MatLab

The file functions and program file used in the previous subsections are the simplest example programs. All MatLab commands contained in them are executed sequentially. To solve many more serious problems, you need to write programs in which actions are performed cyclically or, depending on some conditions, different parts of the programs are executed. Let's look at the main operators that specify the sequence of execution of MatLab commands. Operators can be used both in file procedures and in functions, which allows you to create programs with complex branched structures.

6.1. Loop operator for

An operator is designed to perform a specified number of repeated actions. The simplest use of the for statement is as follows:

for count = start:step:final
MatLab commands
end

Here count is a loop variable, start is its initial value, final is its final value, and step is the step by which count is increased each time the loop is entered. The loop ends as soon as count becomes greater than final. A loop variable can take not only integer values, but also real values ​​of any sign. Let's look at the use of the for loop operator using some typical examples.
Let it be necessary to derive a family of curves for , which is specified by a function depending on the parameter for parameter values ​​from -0.1 to 0.1.
Type the text of the file procedure in the M-file editor and save it in the file FORdem1.m, and run it for execution (from the M-file editor or from the command line by typing the FORdem1 command in it and pressing ):

% file program for constructing a family of curves
x = ;
for a = -0.1:0.02:0.1
y = exp(-a*x).*sin(x);
hold on
plot(x, y)
end

Note 4

The M-file editor automatically suggests placing statements inside the loop, indented from the left edge. Use this feature to make it easier to work with program text.

As a result of executing FORdem1, a graphical window will appear that contains the required family of curves.

Write a file program to calculate the sum

The algorithm for calculating the sum uses the accumulation of the result, i.e. first the sum is zero ( S= 0), then into a variable k a unit is entered and 1/ is calculated k!, is added to S and the result is again entered into S. Further k increases by one, and the process continues until the last term is 1/10!. The Fordem2 file program shown in the following listing calculates the required amount.

Listing of the Fordem2 file program for calculating the amount

% file program for calculating the amount
% 1/1!+1/2!+ … +1/10!

% Reset S to accumulate amount
S = 0;
% accumulation of amount in cycle
for k = 1:10
S = S + 1/factorial(k);
End
% output the result to the command window S

Type the program file in the M-file editor, save it in the current directory in the file Fordem2.m and execute. The result will be displayed in the command window, because in the last line of the file program S contains no semicolon to display the value of the variable S

Note that other lines of the file program that would cause intermediate values ​​to be printed to the screen are terminated with a semicolon to suppress output to the command window.

It is no coincidence that the first two lines with comments are separated by a blank line from the rest of the program text. They are the ones that are displayed when the user uses the help command from the command line to obtain information about what Fordem2 is doing

>> help Fordem2
file program for calculating the sum
1/1!+1/2!+ … +1/10!

When writing file programs and file functions, do not neglect comments!
All variables used in the file program become available in the working environment. They are so-called global variables. On the other hand, the file program can use all the variables entered in the work environment.

Consider the problem of calculating the sum, similar to the previous one, but depending on the variable x

To calculate this amount in the Fordem2 file program, you need to change the line inside the for loop to

S = S + x.^k/factorial(k);

Before running the program, you must define a variable x on the command line using the following commands:

>> x = 1.5;
>>Fordem2
S=
3.4817

As x may be a vector or a matrix, since in the Fordem2 file program element-by-element operations were used when accumulating the sum.

Before starting Fordem2, you must assign a variable x some value, and to calculate the sum, for example, from fifteen terms, you will have to make changes to the text of the file program. It is much better to write a universal file function that takes as input arguments the value x and the upper limit of the amount, and the weekend - the value of the amount S(x). The sumN function file is shown in the following listing.

Listing of the file function for calculating the sum

function S = sumN(x, N)
% file function to calculate the sum
% x/1!+x^2/2!+ … +x^N/N!
% usage: S = sumN(x, N)

% reset S to accumulate amount
S = 0;
% accumulation of amount in cycle
for m = 1:1:N
S = S + x.^m/factorial(m);
end

The user can learn about using the sumN function by typing help sumN at the command line. The first three lines with comments will be displayed in the command window, separated from the text of the file function by an empty line.

Note that file function variables are not global (m in sumN file function). Trying to view the value of variable m from the command line results in a message that m is not defined. If there is a global variable in the work environment with the same name, defined from the command line or in a file function, then it is not related in any way to the local variable in the file function. As a rule, it is better to format your own algorithms as file functions so that the variables used in the algorithm do not change the values ​​of the global variables of the working environment with the same name.

For loops can be nested within each other, but the variables of the nested loops must be different.

The for loop is useful when performing repeated similar actions when the number of them is predetermined. A more flexible while loop allows you to get around this limitation.

6.2. While loop operator

Let's consider an example of calculating a sum, similar to the example from the previous paragraph. You need to find the sum of a series for a given x(series expansion):
.

The sum can be accumulated as long as the terms are not too small, let's say more modulo. A for loop is not enough here, since the number of terms is unknown in advance. The solution is to use a while loop, which runs while the loop condition is satisfied:

while loop condition
MatLab commands
end

In this example, the loop condition stipulates that the current term is greater than . To write this condition, use the greater than sign (>). The text of the file function mysin, which calculates the sum of a series, is given in the following listing.

Listing of the mysin file function that calculates sine by series expansion

function S = mysin(x)
% Calculation of sine by series expansion
% Usage: y = mysin(x), -pi

S = 0;
k = 0;
while abs(x.^(2*k+1)/factorial(2*k+1))>1.0e-10
S = S + (-1)^k*x.^(2*k+1)/factorial(2*k+1);
k = k + 1;
end

Please note that the while loop, unlike the for loop, does not have a loop variable, so we had to assign k to zero before the start of the loop, and increase k by one inside the loop.
The while loop condition can contain more than just the > sign. To set the conditions for executing a cycle, other relational operations listed in Table 1 are also valid. 1.

Table 1. Relational operations

Setting more complex conditions is done using logical operators. For example, the condition consists of the simultaneous fulfillment of two inequalities and , and is written using the logical operator and

and(x >= -1, x< 2)

or equivalently with &

(x >= -1) & (x< 2)

Logical operators and examples of their use are given in table. 2.

Table 2. Logical operators

Operator

Writing to MatLab

Equivalent entry

Logical "AND"

and(x< 3, k == 4)

(x< 3) & (k == 4)

Logical "OR"

Or(x == 1,x == 2)

(x == 1) | (x == 2)

Negation "NOT"

When calculating the sum of an infinite series, it makes sense to limit the number of terms. If the series diverges because its terms do not tend to zero, then the condition for the small value of the current term may never be satisfied and the program will go into loop. Perform the summation by adding a limit on the number of terms to the while loop condition of the mysin file function:

while (abs(x.^(2*k+1)/factorial(2*k+1))>1.0e-10)&(k<=10000))

or in equivalent form

while and(abs(x.^(2*k+1)/factorial(2*k+1))>1.0e-10), k<=10000)

The organization of repeated actions in the form of cycles makes the program simple and understandable, but it is often necessary to execute one or another block of commands depending on certain conditions, i.e. use algorithm branching.

6.3. Conditional if statement

Conditional operator if allows you to create a branching algorithm for executing commands, in which, when certain conditions are met, the corresponding block of MatLab operators or commands runs.

The if statement can be used in its simple form to execute a block of commands when some condition is satisfied, or in an if-elseif-else construct to write branching algorithms.
Suppose we need to evaluate the expression . Suppose you are performing a calculation in the real number domain and want to display a warning that the result is a complex number. Before calculating the function, you should check the value of the argument x, and display a warning in the command window if the modulus of x does not exceed one. Here you need to use a conditional if statement, the use of which in the simplest case looks like this:

if condition
MatLab commands
end

If the condition is met, then the MatLab commands located between if and end are implemented, and if the condition is not met, then the transition to the commands located after end occurs. When writing a condition, the operations given in table are used. 1.

The file function that checks the value of the argument is shown in the following listing. The warning command is used to display a warning in the command window.

Listing of the Rfun file function that checks the value of an argument

function f = Rfun(x)
% calculates sqrt(x^2-1)
% prints a warning if the result is complex
% usage y = Rfun(x)

% argument check
if abs(x)<1
warning("complex result")
end
% function evaluation
f = sqrt(x^2-1);

Now calling Rfun from an argument less than one will result in a warning message being displayed in the command window:

>> y = Rfun(0.2)
the result is complex
y =
0 + 0.97979589711327i

The Rfun file function only warns that its value is complex, and all calculations with it continue. If a complex result means a calculation error, then you should stop executing the function using the error command instead of warning.

6.4. Branch operator if-elseif-else

In general, the application of the if-elseif-else branch operator looks like this:

if condition 1
MatLab commands
elseif condition 2
MatLab commands
elseif condition 3
MatLab commands
. . . . . . . . . . .
elseif condition N
MatLab commands
else
MatLab commands
end

Depending on the implementation of one or another of N conditions, the corresponding program branch runs if none of the N conditions, then the MatLab commands placed after else are implemented. After executing any of the branches, the operator exits. There can be as many branches as you like or just two. In the case of two branches, the trailing else is used and the elseif is skipped. The statement must always end with end.
An example of using the if-elseif-else statement is given in the following listing.

function ifdem(a)
% example of using the if-elseif-else statement

if (a == 0)
warning("a is equal to zero")
elseif a == 1
warning("a is equal to one")
elseif a == 2
warning("a is equal to two")
elseif a >= 3
warning("a, greater than or equal to three")
else
warning("a is less than three, and not equal to zero, one, two")
end

6.5. Branch operator switch

A switch statement can be used to perform multiple selection or branching . It is an alternative to the if-elseif-else statement. In general, using a switch operator looks like this:

switch switch_expression
case value 1
MatLab commands
case value 2
MatLab commands
. . . . . . . . . . .
case value N
MatLab commands
case (value N+1, value N+2, ...)
MatLab commands
. . . . . . . . . . . .
case (value NM+1, value NM+2,…)
otherwise
MatLab commands
end

In this statement, the value of the switch_expression is first calculated (this can be a scalar numeric value or a string of characters). This value is then compared with the values: value 1, value 2, ..., value N, value N+1, value N+2, ..., value NM+1, value NM+2, ... (which can also be numeric or string) . If a match is found, the MatLab commands following the corresponding case keyword are executed. Otherwise, the MatLab commands located between the otherwise and end keywords are executed.

There can be any number of lines with the keyword case, but there must be only one line with the keyword otherwise.

After executing any of the branches, the switch exits, and the values ​​​​specified in other cases are not checked.

The use of switch is illustrated by the following example:

function demswitch(x)
a = 10/5 + x
switch a
case -1
warning("a = -1")
case 0
warning("a = 0")
case 1
warning("a = 1")
case (2, 3, 4)
warning("a equals 2 or 3 or 4")
otherwise
warning("a is not equal to -1, 0, 1, 2, 3, 4")
end

>> x = -4
demswitch(x)
a =
1
warning: a = 1
>> x = 1
demswitch(x)
a =
6
warning: a is not equal to -1, 0, 1, 2, 3, 4

6.6. Loop break operator break

When organizing cyclic calculations, care should be taken to ensure that no errors occur within the loop. For example, suppose you are given an array x consisting of integers, and you want to generate a new array y according to the rule y(i) = x(i+1)/x(i). Obviously, the problem can be solved using a for loop. But if one of the elements of the original array is zero, then division will result in inf, and subsequent calculations may be useless. This situation can be prevented by exiting the loop if the current value of x(i) is zero. The following program fragment demonstrates the use of the break statement to interrupt a loop:

for x = 1:20
z = x-8;
if z==0
break
end
y = x/z
end

As soon as the variable z becomes 0, the loop is terminated.

The break statement allows you to terminate the execution of for and while loops early. Outside of these loops, the break statement does not work.

When the break statement is used in a nested loop, it only exits the inner loop.

Files are fairly common MATLAB objects. Some file types have already been discussed in previous chapters. This lesson discusses file properties that do not depend on their type and apply to any file.

File usually is a collection of data united by one name. The file type is usually determined by its extension. We consider the file as a whole, although physically on the disk it can be represented by several areas - they say that in this case the file is fragmented.

Before using any file, it must be open, and upon completion of use - closed. Many files can be open and readable at the same time. Let's look at the commands for opening and closing files.

  • Team open name, where name must contain a character array or a character variable, opens files depending on the analysis of the name parameter and the extension in the name name:
    • variable- opens an array named by name in the Array Editor;
    • .mat- opens a file, saves variables in a structure in the workspace;
    • .fig- opens it in the descriptor graphics editor Property Editor;
    • .m- opens the m-file in the editor-debugger;
    • .mdl- opens the model in Simulink;
    • .R- opens, if there is one, an m-file with the same name;
    • .html- opens the HTML document in the help browser.

If files with the extension exist in the MATLAB path, then the file that is returned by the command which name is opened, if not, then the file from the file system. If the file does not have a name extension, then it is opened by the program whose file format would be detected by the which function ("file name"). By default, openother is called for all files with endings other than those listed above. Open calls the functions orepxxx, where xxx is the file extension. The exceptions are workspace variables, for which openvar is called, and drawings, for which openim is called. By creating t-files named orepxxx, users can change how the files are handled and add new extensions to the list. You need to close files opened using open from editors called openxxx.

  • = uigetfile(FILTERSPEC.Title). Opens a dialog with the name Title and a FILTERSPEC filter (for example, a cell array containing file extensions) and returns the user-selected file and its path. Returns FILENAME=0 if the file does not exist or if the user clicked Cancel. = uigetfile(FILTERSPEC, Title. X. Y) places the dialog box at X, Y (pixel coordinates).

Uigetfile("*.m;*.fig;*.mat:*.mdl" , "All MATLAB Files (*.m, *.fig, *.mat. *.mdl)")...

  • = uiputfile(FILTERSPEC. TITLE) saves the file in a user-controlled dialog. The parameters are the same as those in the uigetfile function.
  • Team ui open opens a dialog, and if the user has selected a file with a known extension, calls it using open, or if the file name has an unknown extension, then uigetfile is called. uiopen input arguments can be mat lab, load, figure, simulink, editor. Without input arguments or with a matlab input argument, the dialog box prompts you to select *.m, *.fig, *.mat, *.mdl (if Simulink is installed), *.cdr (if state flow is installed), *.rtw, *. tmf, *.tlc, *.c, *.h, *.ads, *.adb (if Real-Time Workshop is installed). With the load argument - *.mat. With the figure argument, *.fig; simul ink - *.mdl, editor - *.m, *.mdt *.cdr, *.rtw, *.tmf, *.tlc, *.c, *.h, *.ads, *.adb.

Open figure

  • Team uiload opens a file in a user-controlled dialog using the command load.

Function ui import Launches Import Wizard(Import Wizard), which imports from a file in the current folder or the Windows clipboard. It matches the choice Import Data from the menu File or choice Paste Special from the menu Edit MATLAB.

  • ui import (FILENAME)- launches the Import Wizard, opening the file FILENAME. The Import Wizard shows a preview of the data. The data and its representation as MATLAB variables appear in the preview window. The actual data, text, and headers are represented by different MATLAB variables. For ASCII data, you must ensure that the Import Wizard recognizes the column delimiters. On its own, it can only recognize the tab character, space, comma, or semicolon. You need to click on the button Next and in the next window either confirm the choice of separator made by the Wizard, or select Other and enter any separator.
  • ui import (" -file")- first displays a file selection dialog.
  • ui import ("-pastespecial")- first displays the contents of the Windows clipboard for preview.
  • S = ui import (...) stores the resulting variables as fields of the S structure.
  • Team uisave- user-controlled saving (the save command is described in lesson 2) with a Windows dialog.
  • Function saveas- saves the drawing or Simulink model in the desired format on a storage medium or device enabled by print.
  • Function saveas(H, "FILENAME")- saves data in accordance with the descriptor graphics command H in the file FILENAME. The file format is determined by the FILENAME name extension.
  • Function saveas(H. "FILENAME". "FORMAT")- does the same thing, but with the FORMAT parameter (the format is set in the same way as the file name extension and may differ from it). FORMAT takes precedence over filename extension. Function parameters:
    • "fig"- save the drawing (graph) in a binary fig file;
    • "m" or "mfig"- save the drawing in a binary fig-file and create an m-file for loading it;
    • "mmat"- save the drawing in an m-file as a sequence of commands for creating a drawing. May not support the latest graphics features.

Saveas(gcf. "output" , "fig") saveas(gcf, "output" , "bmp")

Command or function delete deletes a file or graphic object.

The most common cause of problems with MATLAB file opening is simply the lack of appropriate applications installed on your computer. In this case, it is enough to find, download and install an application that serves files in the MATLAB format - such programs are available below.

Search system

Enter file extension

Help

Clue

Please note that some encoded data from files that our computer does not read can sometimes be viewed in Notepad. In this way we will read fragments of text or numbers - It is worth checking whether this method also works in the case of MATLAB files.

What to do if the application from the list has already been installed?

Often an installed application should automatically link to a MATLAB file. If this does not happen, then the MATLAB file can be successfully linked manually with the newly installed application. Just right-click on the MATLAB file, and then select the “Choose default program” option from the available ones. Then you need to select the “View” option and find your favorite application. The entered changes must be approved using the "OK" option.

Programs that open a MATLAB file

Windows

Why can't I open a MATLAB file?

Problems with MATLAB files may also have other causes. Sometimes even installing software on your computer that supports MATLAB files will not solve the problem. The reason for the inability to open and work with the MATLAB file may also be:

Inappropriate MATLAB file associations in registry entries
- corruption of the MATLAB file we open
- MATLAB file infection (viruses)
- too little computer resource
- outdated drivers
- removal of the MATLAB extension from the Windows registry
- incomplete installation of a program that supports the MATLAB extension

Fixing these issues should result in MATLAB files being able to open and work with ease. In case your computer still has problems with files, you need to take the help of an expert who will determine the exact cause.

My computer does not show file extensions, what should I do?

In standard Windows system installations, the computer user does not see the MATLAB file extension. This can be successfully changed in the settings. Just go to the "Control Panel" and select "View and Personalization". Then you need to go to "Folder Options" and open "View". In the "View" tab there is an option "Hide extensions of known file types" - you must select this option and confirm the operation by clicking the "OK" button. At this point, the extensions of all files, including MATLAB, should appear sorted by file name.

We hope that we helped you solve the problem with the MATLAB file. If you don't know where you can download an application from our list, click on the link (this is the name of the program) - You will find more detailed information on where to download the secure installation version of the required application.

A visit to this page should help you answer these or similar questions specifically:

  • How to open a file with a MATLAB extension?
  • How to convert a MATLAB file to another format?
  • What is the MATLAB File Format Extension?
  • What programs serve the MATLAB file?

If, after viewing the materials on this page, you still do not receive a satisfactory answer to any of the questions presented above, this means that the information presented here about the MATLAB file is incomplete. Contact us using the contact form and write what information you did not find.

What else could cause problems?

There may be more reasons why you cannot open a MATLAB file (not just the lack of an appropriate application).
Firstly- the MATLAB file may be incorrectly linked (incompatible) with the installed application to serve it. In this case, you need to change this connection yourself. To do this, right-click on the MATLAB file you want to edit, click the option "To open with" and then select the program you installed from the list. After this action, problems with opening the MATLAB file should completely disappear.
Secondly- the file you want to open may simply be damaged. In this case, it would be best to find a new version of it, or download it again from the same source (perhaps for some reason in the previous session the download of the MATLAB file did not finish and it could not be opened correctly).

Do you want to help?

If you have additional information about the MATLAB file extension, we would be grateful if you share it with users of our site. Use the form provided and send us your information about the MATLAB file.