I get an error when I run a Matlab code (attached), that continuosly check and opens two .txt files at a given time interval, (2 seconds) and depending on the result a value comparison between those two files, chose one or another and use it.... Those two files are constantly saved and updated by a Java script at the same time interval of 2 seconds. All the files are located in the same path.
The error I get is: "invalid file identifier. use fopen to generate a valid file identifier
Error in KinectDEMelevation_with_filecomparison2 (line 36) DEM1 = textscan(fid2,formatSpec,'HeaderLines',6,'Delimiter','\b'); "
The code is:
DEM = GRIDobj('kinectDEM0.txt');
clims = [-30 140];
imagesc(DEM,clims);
colormap(jet);
hold on
while(1)
tic
% clear all
% clf
% load('MyColormaps','mycmap');
%% Get kinectDEM0 data
% Open 'kinectDEM0.txt'
fid1 = fopen('kinectDEM0.txt', 'r+');
% Read data in from the .txt file
formatSpec = '%n';
DEM0 = textscan(fid1,formatSpec,'HeaderLines',6,'Delimiter','\b');
% Extract data from DEM0
DEM0Data = DEM0{1,1}(200:100:287800,1);
% Close 'kinectDEM0.txt'
fclose(fid1);
%% Get kinectDEM1 data
% Open 'kinectDEM1.txt'
fid2 = fopen('kinectDEM1.txt', 'r+');
% Read data in from the .txt file
formatSpec = '%n';
DEM1 = textscan(fid2,formatSpec,'HeaderLines',6,'Delimiter','\b');
% Extract data from DEM1
DEM1Data = DEM1{1,1}(200:100:287800,1);
% Close 'kinectDEM1.txt'
fclose(fid2);
%% Compare data, a logical array return 1 for true (points that has been changed), 0 for false
test = eq(DEM0Data,DEM1Data);
num = sum(test); % numbers of point in the scene that has been changed
threshold = 2900; % after this threshold update the image
if num > threshold
DEM = GRIDobj('kinectDEM1.txt');
clf
clims = [-30 140];
imagesc(DEM,clims);
colormap(jet);
hold on
end
T = toc;
pause(2 - T);
end
How can I fix it?
Thanks