Using size on a data file, etc... Could someone explain what each step here does exactly?

2 Ansichten (letzte 30 Tage)
info = importdata('......txt')
[f_max,~]=size(info.data);
%sample frequency of 120Hz
time_step=1/120;
t=(1:f_max)*time_step;

Akzeptierte Antwort

Walter Roberson
Walter Roberson am 1 Dez. 2020
importdata() in some circumstances returns a struct that has a field named data that holds whatever importdata() decided was numeric data.
Caution: if you were to remove the other lines in the file, such as header lines, then even though the remaining lines would be the same numeric lines, importdata() might decide to return a plain numeric array instead of a struct with a data field. Because of this fundamental uncertainty, I recommend against using importdata()
Anyhow, after the importdata() call, info is a plain struct scalar struct array, and info.data is accessing the numeric part of what was read in. There is nothing magic about size(info.data) -- it is the same as size() of any variable.
The syntax used
[f_max,~]=size(info.data);
has the same effect as
f_max = size(info.data, 1);
which returns the number of rows the variable has. This is not generally true of size() for other dimensions. For example,
[~, f_max] = size(info.data)
is not equivalent to
f_max = size(info.data, 2)
in the case that info.data has 3 or more dimensions (which would not happen for importdata() though.)
The rest of the lines are creating a vector t in which each entry is the row number divided by 120, representing 120 Hz. Note that the first entry would be 1/120 . When dealing with time data, that is not necessarily wrong, but it would be more common for the time vector to be
t=(0:f_max-1)*time_step;
which is very similar except that the time starts from 0

Weitere Antworten (0)

Kategorien

Mehr zu Startup and Shutdown finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by