Struct contents reference from a non-struct array object. Error
信息
此问题已关闭。 请重新打开它进行编辑或回答。
显示 更早的评论
Hello, my friends and I are writing this script for our Accelerometer Lab. Both of my partners are able to run this section of script just fine but on my MatLab it will not work for some reason even though we all have the same files. The "Struct contents reference from a non-struct array object." error appears on the line the defines "time." Could somebody offer some insight for why this maybe happening? Below is the code and the file that is trying to be accessed.
clc
clear
close all
filename = 'Accel2.CSV'; %Plot Bouy accelerometer data
data = importdata(filename);
Fs= 100;
*time = 100*(data.data(:,1)*1/Fs);*
acc_z = data.data(:,4)-1014.4;
figure
plot(time,acc_z)
title('Frequency Vs. Time of Bouy Accelerometer Data')
xlabel('Time (s)')
ylabel('Z Axis Acceleration (m/s^2)')
figure
plot(acc_z)
title('Frequency Vs. Index of Bouy Accelerometer Data')
xlabel('Index')
ylabel('Z Axis Acceleration (m/s^2)')
0 个评论
回答(1 个)
Star Strider
2018-3-25
Your file has 18 header lines, and every other row of the original ‘data’ matrix are NaN(1:4).
Try this:
Data = importdata('Accel2.csv', ',', 18);
data = Data.data;
data = data(all(~isnan(data),2),:);
Fs= 100;
time = 100*data(:,1)/Fs;
acc_z = data(:,4)-1014.4;
figure
plot(time,acc_z)
title('Frequency Vs. Time of Bouy Accelerometer Data')
xlabel('Time (s)')
ylabel('Z Axis Acceleration (m/s^2)')
figure
plot(acc_z)
title('Frequency Vs. Index of Bouy Accelerometer Data')
xlabel('Index')
ylabel('Z Axis Acceleration (m/s^2)')
0 个评论
此问题已关闭。
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!