how to read data from a .mat file

조회 수: 1,432 (최근 30일)
Naema
Naema 2015년 4월 1일
댓글: Naema 2015년 4월 1일
Hi: I have a .mat file named Ey1a which I need to use it in my code as one of the inputs. The file contains complex data (real and imaginary).I read the file like this:
dlmread Ey1a.mat
but I had this error:
Mismatch between file and format string.
Trouble reading number from file (row 1, field 1) ==> MATLA
Error in ==> fiber_commentedoriginal at 38 dlmread Ey1a.mat;
also, I need to use the conjugate of Ey1a in my code, so how to do this as I can not load the Ey1a.mat file itself

채택된 답변

per isakson
per isakson 2015년 4월 1일
Try
S = load('Ey1a.mat');
and see help for load
  댓글 수: 22
Stephen23
Stephen23 2015년 4월 1일
편집: Stephen23 2015년 4월 1일
@Naema: when you load the .MAT file using load:
S = load(...);
it puts all of the data (that is in the .MAT file) into a structure named S. This is what the documentation clearly states.
The structure S is not your original data array, but a container that contains your data array. A structure is like a box: and just like a box can contain something, so can a structure hold your data. When you wish to access your data, you first need to get it out of the structure, just like you would get something out of the box before you can use it. To access data in a structure we use this notation:
S.variable
where in your case the variable is the name Ey1a or something similar. So this should work for accessing the data in your structure:
S.Ey1a
If you try to use S for your calculation, then this is still just the structure and not your data that is inside the structure, thus the error. You need to get your data out of the structure before you can use it.
You can also have a look inside a structure in your workspace (double click to open it up), or use the command fieldnames(S) to get a list of all of the variables that are contained in the structure.
Naema
Naema 2015년 4월 1일
Stephen: Yes, it works now. Before I multiply Z and S . I had to access both of them and then multiply them together.

댓글을 달려면 로그인하십시오.

추가 답변 (4개)

James Tursa
James Tursa 2015년 4월 1일
편집: James Tursa 2015년 4월 1일
Use the load function to read .mat files. E.g.,
load Ey1a.mat
  댓글 수: 4
Naema
Naema 2015년 4월 1일
It shows this:
Name Size Bytes Class Attributes
Ey1a 3001x3001 144096016 double complex
LUI PAUL
LUI PAUL 2015년 4월 1일
편집: LUI PAUL 2015년 4월 1일
load('Eyla.mat');
Eyla=conj(Eyla);

댓글을 달려면 로그인하십시오.


Vinod Sudheesh
Vinod Sudheesh 2015년 4월 1일
You could use the "load" command to read data stored in a MAT file.
>> load Ey1a.mat
The "dlmread" function is used for reading ASCII delimited file.

LUI PAUL
LUI PAUL 2015년 4월 1일
for other directory.....
load('D:\data_file\Eyla.mat')
for current directory load('Eyla.mat');
or follow the figure....

LUI PAUL
LUI PAUL 2015년 4월 1일
to get conjugate
load('Eyla.mat');
Eyla=conj(Eyla);

카테고리

Help CenterFile Exchange에서 Workspace Variables and MAT-Files에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by