I wanna make a .mat file

7 Ansichten (letzte 30 Tage)
MERVE
MERVE am 21 Nov. 2022
Kommentiert: Merve ozdas am 21 Nov. 2022
Hi, how can I comprise of a .mat file for my data. THank you.
  5 Kommentare
Merve ozdas
Merve ozdas am 21 Nov. 2022
eeg=csvread("eeg.csv");
save('eeg_file.mat','eeg')% this 'eeg' is from variable that I defined.
Image Analyst
Image Analyst am 21 Nov. 2022
Yes, that will work. And like I showed in my answer, you can simply list all the variables after that if you want any additional variables changed. So if it's working for you, you can click the "Accept this answer" for my answer or one you think is better than mine.

Melden Sie sich an, um zu kommentieren.

Antworten (4)

John D'Errico
John D'Errico am 21 Nov. 2022
help save
SAVE Save workspace variables to file. SAVE(FILENAME) stores all variables from the current workspace in a MATLAB formatted binary file (MAT-file) called FILENAME. Specify FILENAME as a character vector or a string scalar. For example, specify FILENAME as 'myFile.mat' or "myFile.mat". SAVE(FILENAME,VARIABLES) stores only the specified variables. Specify FILENAME and VARIABLES as character vectors or string scalars. SAVE(FILENAME,'-struct',STRUCTNAME,FIELDNAMES) stores the fields of the specified scalar structure as individual variables in the file. If you include the optional FIELDNAMES, the SAVE function stores only the specified fields of the structure. You cannot specify VARIABLES and the '-struct' keyword in the same call to SAVE. SAVE(FILENAME, ..., '-append') adds new variables to an existing file. You can specify '-append' with additional inputs such as VARIABLES, '-struct', FORMAT, or VERSION. SAVE(FILENAME, ..., FORMAT) saves in the specified format: '-mat' or '-ascii'. You can specify FORMAT with additional inputs such as VARIABLES, '-struct', '-append', or VERSION. SAVE(FILENAME, ..., VERSION) saves to MAT-files in the specified version: '-v4', '-v6', '-v7', or '-v7.3'. You can specify VERSION with additional inputs such as VARIABLES, '-struct', '-append', '-nocompression', or FORMAT. SAVE(FILENAME, ..., '-nocompression', '-v7.3') saves to MAT-files version 7.3 without compression. You can specify '-nocompression' with additional inputs such as VARIABLES and '-append'. This option is supported for MAT-files version 7 and above. SAVE FILENAME ... is the command form of the syntax, for convenient saving from the command line. With command syntax, you do not need to enclose FILENAME in single or double quotation marks. Separate inputs with spaces instead of commas. Do not use command syntax if inputs such as FILENAME are variables. Inputs: FILENAME: If you do not specify FILENAME, the SAVE function saves to a file named matlab.mat. If FILENAME does not include an extension and the value of format is '-mat' (the default), MATLAB appends .mat. If filename does not include a full path, MATLAB saves in the current folder. You must have permission to write to the file. VARIABLES: Save only selected variables from the workspace. Use one of the following forms: V1, V2, ... Save the listed variables. Use the '*' wildcard to match patterns. For example, save('A*') saves all variables that start with A. '-regexp', EXPRESSIONS Save only the variables that match the specified regular expressions. SAVE treats all inputs as regular expressions except the optional FILENAME and STRUCTNAME. The FILENAME input must appear first. For more information on regular expressions, type "doc regexp" at the command prompt. '-struct', STRUCTNAME, FIELDNAMES: Save the fields of a scalar structure as individual variables in the file. FIELDNAMES is optional; specify to save only selected fields. FIELDNAMES use the same forms as VARIABLES. '-append': Add data to an existing file. For MAT-files, '-append' adds new variables to the file or replaces the saved values of existing variables with values in the workspace. For ASCII files, '-append' adds data to the end of the file. FORMAT: Specify the format of the file, regardless of any specified extension. Use one of the following combinations: '-mat' Binary MAT-file format (default). '-ascii' 8-digit ASCII format. '-ascii', '-tabs' Tab-delimited 8-digit ASCII format. '-ascii', '-double' 16-digit ASCII format. '-ascii', '-double', '-tabs' Tab-delimited 16-digit ASCII format. For ASCII file formats, the SAVE function has the following limitations: * Each variable must be a two-dimensional double or char array. * MATLAB translates characters to their corresponding internal ASCII codes. For example, 'abc' appears in an ASCII file as: 9.7000000e+001 9.8000000e+001 9.9000000e+001 * The output includes only the real component of complex numbers. * If you plan to use the LOAD function to read the file, all variables must have the same number of columns. '-nocompression': Save data to a MAT-file without compression. The '-nocompression' option is only supported for MAT-files version 7 and above. VERSION: Create a MAT-file that you can load into an earlier version of MATLAB or that supports specific features. The following table shows the available MAT-file version options and the corresponding supported features. | Can Load in | Option | Versions | Supported Features ---------+--------------+---------------------------------------------- '-v7.3' | 7.3 or later | Version 7.0 features plus support for | | data items greater than or equal to 2GB on | | 64-bit systems. ---------+--------------+---------------------------------------------- '-v7' | 7.0 or later | Version 6 features plus data compression and | | Unicode character encoding. Saving variables | | without compression is also supported using | | the '-nocompression' flag. ---------+--------------+---------------------------------------------- '-v6' | 5 or later | Version 4 features plus N-dimensional arrays, | | cell and structure arrays, and variable names | | greater than 19 characters ---------+--------------+---------------------------------------------- '-v4' | all | Two-dimensional double, character, and | | sparse arrays If any data items require features that the specified version does not support, MATLAB does not save those items and issues a warning. You cannot specify a version later than your version of MATLAB software. To view or set the default version for MAT-files, select File > Preferences > General > MAT-Files. Examples: % Save all variables from the workspace to test.mat: save test.mat % Save two variables, where FILENAME is a variable: savefile = 'pqfile.mat'; p = rand(1, 10); q = ones(10); save(savefile, 'p', 'q'); % Save the fields of a structure as individual variables: s1.a = 12.7; s1.b = {'abc', [4 5; 6 7]}; s1.c = 'Hello!'; save('newstruct.mat', '-struct', 's1'); % Save variables whose names contain digits: save myfile.mat -regexp \d See also LOAD, MATFILE, WHOS, REGEXP, HGSAVE, SAVEAS, WORKSPACE, CLEAR. Documentation for save doc save Other uses of save autosar.arch.Model/save COM.com/save COM/save controllib.widget.internal.cstprefs.ToolboxPreferences/save DataRecorder/save icomm/save imaq/save instrument/save matlab.diagram.ClassViewer/save rmidata/save sim3d.Actor/save Simulink.Bus/save Simulink.CodeImporter/save Simulink.interface.dictionary.Migrator/save Simulink.interface.Dictionary/save Simulink.ModelWorkspace/save Simulink.sdi/save slcoverage.Filter/save slreq.LinkSet/save slreq.ReqSet/save systemcomposer.allocation.AllocationSet/save systemcomposer.analysis.ArchitectureInstance/save systemcomposer.arch.Model/save systemcomposer.profile.Profile/save vrworld/save
  3 Kommentare
Walter Roberson
Walter Roberson am 21 Nov. 2022
Sure, that should work.
Generally speaking, modern style would be to use readmatrix() or readtable() to read csv files, depending on whether the data is expected to be all numeric or not.
csvread() is a wrapper around dlmread() which in turn is a wrapper around fopen() / textscan() / fclose() . And those approaches are still valid -- but the newer approaches are more flexibile. For example the newer functions can be passed a url, and the newer functions are able to handle missing entries, or handle unexpected text in numeric fields.
Merve ozdas
Merve ozdas am 21 Nov. 2022
okay thank you Walter :)

Melden Sie sich an, um zu kommentieren.


KSSV
KSSV am 21 Nov. 2022
A = rand(10) ;
str = 'The above is matrix' ;
save test.mat ; % save A, str into mat file
load test.mat ; % load the mat file

Jan
Jan am 21 Nov. 2022
Bearbeitet: Jan am 21 Nov. 2022
In Matlab this is easy:
data = magic(4); % Arbitrary test data
save('file.mat', 'data')

Image Analyst
Image Analyst am 21 Nov. 2022
For example you want to make a mat file called 'answers.mat' containing variables var1 and var2:
save('answers.mat', 'var1', 'var2');

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by