Why is this code not reading the csv file?

Hi I'm new to MatLab, and I have been trying to run the code inorder to create a PSD plot. However, I can't really figure out where or why it is falling down. Anyone have any ideas or know why? I have attached a picture of the code and the table in matlab...

답변 (1개)

Alex Mcaulley
Alex Mcaulley 2019년 10월 29일

0 개 추천

The images are useless, but the error is clear, your variable tdata doesn't exist. I guess you need to change this line:
tdata = readtable(fname);

댓글 수: 5

Ryan Marsden
Ryan Marsden 2019년 10월 29일
I have attached the code if that is better for you? i have added that line in and it still isnt working?
Alex Mcaulley
Alex Mcaulley 2019년 10월 29일
편집: Alex Mcaulley 2019년 10월 29일
What is the error know? Please, copy-paste the full error text (Note that we don't have the csv file to test it)
Ryan Marsden
Ryan Marsden 2019년 10월 30일
Warning: Column headers from the file were modified to make them valid MATLAB identifiers before creating variable names for the table.
The original column headers are saved in the VariableDescriptions property.
Set 'PreserveVariableNames' to true to use the original column headers as table variable names.
Warning: Column headers from the file were modified to make them valid MATLAB identifiers before creating variable names for the table.
The original column headers are saved in the VariableDescriptions property.
Set 'PreserveVariableNames' to true to use the original column headers as table variable names.
Unrecognized function or variable 'fs'.
Error in PSD1 (line 7)
dt=1/fs
Sorry for the delayed response.
Ryan Marsden
Ryan Marsden 2019년 10월 30일
clear
clc
fname='ADI 3DOF with mass2_0000.csv';
readtable(fname);
tdata=readtable(fname);
[nt,n]=size(tdata);
dt=1/fs
Td=nt*dt;
M=2;
nw=floor(nt/M);
for i=1:n
tdata1=reshape(tdata(1:nw*M,i),nw,M);
F=fft(tdata1)*sqrt(2*dt/nw);
SF=abs(F).^2;
S(:,i)=mean(SF,2);
end
df=1/(nw*dt);
ff=0:df:(nw-1)*df;
semilogy(ff,sqrt(S));
xlim([0.1,10])
ylim([0.1,0.00001])
xlabel('frequency(Hz)')
ylabel('PSD g/sqrt(Hz)')
Ryan Marsden
Ryan Marsden 2019년 10월 30일
I guess to give a bit of context, I have been using another code which can import the files I need can process them. However, the PSD plot is not the in the sytle we would like (in terms of axis) so I have been give this, which is the older code to try and made the PSD plot. The new code uses serveral different .m files and I am struggling to follow that code through. Hence why i have opted to try and modify this on.

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

카테고리

제품

릴리스

R2019b

태그

질문:

2019년 10월 29일

댓글:

2019년 10월 30일

Community Treasure Hunt

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

Start Hunting!

Translated by