help with looping the fopen and fclose to draw a continuous graph

2 vues (au cours des 30 derniers jours)
Likitha TG
Likitha TG le 9 Août 2019
hey,
i have 288 files which contain 6050 lines, out of which first 50 lines are textual data
and from 50th line to 6000 lines is x,y,z coordinate data, i have to extract data of x,y,z from all the 288 files so that i can draw a continuous plot of x,y,z on after the other.
data files are named 1_1, 1_2, 2_1, 2_2 etc etc
clear all
clc
files = dir('1_1.txt') ;
fid = fopen( '1_1.txt' );
cac = textscan(fid,'%f%f%f', 'Headerlines',50, 'CollectOutput',true );
fclose( fid );
num = cac{1};
x = num(:,1);
y = num(:,2);
plot(x,y)
i wrote this logic for the first set of data but im not able to loop this to extract the continuous plot. can someone help me?
thank you
  3 commentaires
Likitha TG
Likitha TG le 9 Août 2019
its an hourly testing data,
so 1_1 denotes the data at the start of the hour
1_2 denotes the data at the 50 th min
2_1 denotes the start of the second hour and so on
dpb
dpb le 9 Août 2019
Modifié(e) : dpb le 9 Août 2019
So, what happens in numbering system between hour 9 and 10, minute 9 and 10, ... ?
>> for i=1:15,fid=fopen(num2str(i,'1_%d.txt'),'w');fid=fclose(fid);end
>> d=dir('1_*.txt');
>> {d.name}.'
ans =
15×8 char array
'1_1.txt '
'1_10.txt'
'1_11.txt'
'1_12.txt'
'1_13.txt'
'1_14.txt'
'1_15.txt'
'1_2.txt '
'1_3.txt '
'1_4.txt '
'1_5.txt '
'1_6.txt '
'1_7.txt '
'1_8.txt '
'1_9.txt '
>>

Connectez-vous pour commenter.

Réponses (1)

Kavya Vuriti
Kavya Vuriti le 13 Août 2019
If the order of processing is not important, then you can use dir function to list all the files in a folder. Output of this function is a structure which has a field “name”. This field can be used in fopen function to open the file. Then extract the data using textscan function. To get a continuous plot, store the x and y values extracted from the files in arrays “x” and “y” and plot them after the loop terminates. You can also try using hold on command to get plot in the same figure window with same axes.

Catégories

En savoir plus sur Low-Level File I/O dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by