Getting an error on reading a file

1 view (last 30 days)
Nikhil Singh
Nikhil Singh on 23 Nov 2015
Edited: Walter Roberson on 23 Nov 2015
I am using the current matlab script in which the file imu_data.bin is already existing
filename = 'imu_data.bin';
[inertial_data,time_stamps,raw_data]=parse_imu_data(filename);
%delete(filename);
i=0;
while i >=0
filename1 = 'inertial_data.bin' ;
file1 = fopen(filename1, 'w');
fwrite(file1,fread(inertial_data,'uint8'),'uint8');
i = i+1;
fclose(file1);
end
% Plot data in SI units
figure(1),clf, hold on
plot(inertial_data(1:3,:)');
plot(sqrt(sum(inertial_data(1:3,:).^2)),'c');
grid on
title('Accelerometer readings');
xlabel('sample number')
ylabel('a [m/s^2]');
figure(2), clf, hold on
plot(inertial_data(4:6,:)'*180/pi);
plot(sqrt(sum((inertial_data(4:6,:)*180/pi).^2)),'c');
grid on
title('Gyroscope readings');
xlabel('sample number')
ylabel('\omega [deg/s]');
figure(3),clf, hold on
subplot(2,1,1);
plot(double(time_stamps)'/64e6,'b-');
grid on
title('Time stamps');
xlabel('sample number')
ylabel('[s]');
subplot(2,1,2);
dt = diff(double(time_stamps)');
for i=1:numel(dt)
if dt(i)<0
dt(i) = dt(i)+2^32;
end
end
plot(dt/64e6,'b-');
grid on
title('Time differentials');
xlabel('sample number')
ylabel('[s]');
figure(4), clf, hold on
plot(sqrt(sum((inertial_data(4:6,:)*180/pi).^2)),'c');
grid on
Iam getting the following error message
"Error using fread
Invalid file identifier. Use fopen to generate a valid file identifier.
Error in line
fwrite(file1,fread(inertial_data,'uint8'),'uint8');"

Answers (1)

Walter Roberson
Walter Roberson on 23 Nov 2015
Opening inertial_data.bin for writing failed. You should check to see which directory you are cd()'d to, as you might be in a directory that you do not have permission to write in.
  2 Comments
Nikhil Singh
Nikhil Singh on 23 Nov 2015
Edited: Walter Roberson on 23 Nov 2015
Mr. Walter I have tried the same thing earlier in the same directory in another script there it work fine.
filename = 'imu_data.bin';
file = fopen(filename, 'rb');
ctr = 0;
while ~feof(file)
f = fread(file,8,'uint8');
disp(f)
ax = fread(file,1,'single');
disp(ax)
ay = fread(file,1,'single');
disp(ay)
az = fread(file,1,'single');
disp(az)
gx = fread(file,1,'single');
disp(gx)
gy = fread(file,1,'single');
disp(gy)
gz = fread(file,1,'single');
disp(gz)
fread(file,1,'uint16');
filename1 = 'imu_dat.bin';
file2 = fopen(filename1, 'w');
ctr = ctr + fwrite(file2,fread(file,'uint8'),'uint8');
fclose(file2);
end
this is the script Which I had used. its working good and The data is also correct. But for I don't know what happened second time.
Walter Roberson
Walter Roberson on 23 Nov 2015
Edited: Walter Roberson on 23 Nov 2015
Please show the result of
exist('inertial_data.bin')
dir('inertial_data.bin')
fileattrib('inertial_data.bin')
fileattrib('.')

Sign in to comment.

Categories

Find more on Interactive Control and Callbacks in Help Center and File Exchange

Tags

Products

Community Treasure Hunt

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

Start Hunting!