Import Data Error (Attempt to reference field of non-structure array)

6 views (last 30 days)
This is my code:
%
E1 = importdata('shaker18.dat');
Data = E1.data;
FreqE1 = Data(1:end-1,2); %frequency (Hz)
AmpEA1 = Data(1:end-1,3); %amplitude of accelerometer (V)
AmpEH1 = Data(1:end-1,4); %amplitude of hammer (V)
%
When I go to import my data, I get an error saying "Attempt to reference field of non-structure array." I know how to import data because I've done it for other files. The data in the file looks fine. There are 4 columns and 23 rows and there is a value for each space, so I don't know what to do. All help is appreciated!

Answers (1)

Walter Roberson
Walter Roberson on 8 Nov 2013
In the importdata documentation, have a look at "Import a Text File and Return Detected Delimiter". You can see there that in at least some cases, the data can be returned as a plain numeric array rather than a structure.
if isstruct(E1)
Data = E1.data;
else
Data = E1;
end

Categories

Find more on Data Types in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!