Hi there,
So far I have written one function to read in any kind of txt file, which is created by another software (Example is attached, yet in the future these files will be a lot larger). Then, the data was added into the workspace in Matlab. The second script, which I wrote, uses the data, which was created, and plots it continously. Both of these scripts worked independently real well.
Now, I tried to merge these two scripts, so that the data shall be read from the txt file and be plotted at the same time (thats why I start the function with a while cycle).
The txt file, which is created in another program, appends a new row of data every 3 seconds. Ideally, my function will read and update the plot at the same rate.
This is my code:
function [data,Nrows] = ReadPlotTempData(FileName)
count=0;
while (1)
fid = fopen(FileName);
Nrows = numel(textread(FileName,'%1c%*[^\n]'))
for i = 1:15
tline = fgetl(fid);
end
data = zeros(Nrows-15,20);
for i = 1:Nrows-15
tline = fgetl(fid);
k = strfind(tline, ',');
restline = tline((k(29)+1):(k(49)));
data(i,:) = str2num(restline);
end
fclose(FileName)
figure (1)
[hc hc] = contourf(data,100)
colorbar;
caxis auto
legend ('Temperatur in C°')
set (hc,'Linestyle','none');
set (gca,'fontsize',14);
xlabel ('Anzahl der Sensoren', 'fontsize',16);
ylabel ('Zeitreihe', 'fontsize', 16);
colormap jet; colorbar;
drawnow
count=count+1
end
end
My problem / question now is: In the first part of the function, I have to define the dataset, which will be created (TD23111501). Later, when creating the plot, I want to use this data TD23111501 and plot it. However, it doesn't work. Is there another way of defining the dataset and retrieving the data within the same function? Or is it even not possible at all? Thank you for your help
1 Comment
Direct link to this comment
https://www.mathworks.com/matlabcentral/answers/265271-how-can-i-read-in-a-txt-file-which-is-being-created-by-a-different-programm-and-plot-the-numeric-d#comment_338103
Direct link to this comment
https://www.mathworks.com/matlabcentral/answers/265271-how-can-i-read-in-a-txt-file-which-is-being-created-by-a-different-programm-and-plot-the-numeric-d#comment_338103
Sign in to comment.