MATLAB Answers

I have .mat file that has a size of 1374x2. How do I load this in to variable that can be used inside a function?

1 view (last 30 days)
Sylvester Selvanathan Pinto Stephen
Answered: Guru Mohanty on 17 Jan 2020
x = load ('filename');
will this make 'x' have 1374x2 values?

  3 Comments

dpb
dpb on 15 Sep 2019
Yes. No. Maybe. Read the documentaion for load
If 'filename' is a .mat file, then x will be a structure array, the fields of which are whatever variables are in the .mat file.
if filename is an ASCII file, then data are returned as an m-by-n array of type double. m is equal to the number of *DATA* lines in the file, and n is equal to the number of values on a line. Only numeric data can be read this way.
(Fixup for Walter's note...)
Walter Roberson
Walter Roberson on 15 Sep 2019
"m is equal to the number of lines in the file"
Non-comment lines. load() of a recognized text file skips lines that begin with %
Sylvester Selvanathan Pinto Stephen
Let me rephrase my question..
I have a .mat file which has 1374 rows and 2 columns which have only numeric data.
I want to load this into a variable which has the same size.
I tried this
CycleName = load('epa_city','-ascii')
Error using load
Number of columns on line 2 of ASCII file epa_city must be the same as previous lines.
How should I proceed?

Sign in to comment.

Answers (1)

Guru Mohanty
Guru Mohanty on 17 Jan 2020
Hi, I understand you are getting error in loading a MAT file. Here is a sample code for this, in which MAT file is created using random data. You can use both load and matfile functions.
%% Create input MAT file
clear all;
val=randi(100,1374,2);
save('val.mat','val');
%% Load MAT file
clear all;
mat_var = load('val.mat');
C = mat_var.val;

  0 Comments

Sign in to comment.

Sign in to answer this question.


Translated by