Hello, my programme is supposed to read data from a txt file and create plots. Everytime I run the programme, I get an error pasted at the bottom of the code. plz help. I ve attached te txt file also.

1 view (last 30 days)
clear;
close all;
[filename, pathname] = uigetfile('*.txt','*');
addpath(pathname); % Read txt file from anywhere of the directories
XX = dlmread(filename,'\t',1,0);
Fs=200; % scan frequency (200)
n=0.01:1/Fs:5;
%%%%%READ LABVIEW TIME DOMAIN DATA AND STORE IN MATRIX %%%%%
xn=XX(:,1);
%%%%%PLOT POWER SPETRA %%%%%
window=boxcar(length(xn)); %¾ØÐδ°
nfft=1024000;
[Pxx,f]=periodogram(xn,window,nfft,Fs); %Ö±½Ó·¨
figure(1)
subplot(2,1,1)
plot(n,xn),Title('Acceleration-time history'),xlabel('Time(Sec)'),ylabel('Acceleration (g)')
%axis([0 5,-0.5 0.5]);
grid
subplot(2,1,2)
plot(f,Pxx),Title('Acceleration spectrum'),xlabel('Frequency(Hz)'),ylabel('Normalised Acceleration^2/Hz')
axis([0 25,0 0.001]);
text(16,0.0008,'14.64', 'FontSize',16)
grid
%GET THE NATURAL FREQUENCY%
pmax=max(Pxx(:,1)); %ÇóµÚ1ÁеÄ×î´óÖµ
fr=find(Pxx(:,1)>=pmax); %ÕÒµ½×î´óÖµµÄÐкÅ
w=f(fr,:) %È¡¾ØÕóµÄÄÇÐÐ
%ERROR that i get:
>> programe
Error using dlmread (line 139)
Mismatch between file and format string.
Trouble reading number from file (row 1u, field 1u) ==> x,y,z,x,y,z,x,y,z,\n
Error in programe (line 7)
XX = dlmread(filename,'\t',1,0);

Answers (1)

Walter Roberson
Walter Roberson on 29 Nov 2013
You are using dlmread() to read the file. dlmread() is only for numeric information. Line 139 of your file is the line
x,y,z,x,y,z,x,y,z,
which is not numeric.
You will need to remove that line, or you will need to change your program to not use dlmread()
  2 Comments
Munal
Munal on 29 Nov 2013
Now there is a new error: >> programe Error using dlmread (line 139) Mismatch between file and format string. Trouble reading number from file (row 2u, field 1u) ==> ,-0.031052,-0.988647,0.007066,-0.009581,-0.985219,0.003722,-0.021470,-0.003429,\n
Error in programe (line 7) XX = dlmread(filename,'\t',1,0);
Walter Roberson
Walter Roberson on 29 Nov 2013
dlmread() is not suitable for files that have missing information. You will need to switch to textscan() instead
numcol = 10;
fmt = repmat('%f', 1, numcol);
fid = fopen(filename, 'rt');
datacell = textscan(fid, fmt, 'Delimiter', ',', 'EmptyValue', nan, 'CollectOutput', 1);
fclose(fid);
XX = datacell{1};
This will put nan in each of the places that data was not available.

Sign in to comment.

Categories

Find more on Characters and Strings in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!