Bonjour à tous,
Je débute un stage et dans cette perspective je dois pouvoir lire des fichiers CSV. Cependant les fichiers sont trop volumineux et je ne peux pas utiliser la fonction csvread de matlab. En fait on m'impose d'utiliser le script suivant :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42 fid=fopen('test.csv','r'); fid0=fopen('PhData.int','w'); fid1=fopen('Imp1.int','w'); fid2=fopen('Imp2.int','w'); fid3=fopen('Imp3.int','w'); fid4=fopen('Imp4.int','w'); fid5=fopen('Imp5.int','w'); fid6=fopen('Imp6.int','w'); Imp=zeros(6,1); for k=0:5 tline = fgetl(fid); if ~ischar(tline), break, end disp(tline) end Num=0; % Pour ce fichier la valeur max de Num est 3942351!!! while 1 Num=Num+1 tline = fgetl(fid); if ~ischar(tline), break, end disp(tline); ind = find(tline==','); ph = str2num(tline(1:ind(1)-1)); if (rem(Num,50)==1) fwrite(fid0,ph,'short'); end; Imp(1) = str2num(tline(ind(1)+1:ind(2)-1)); for k=2:6 Imp(k-1) = str2num(tline(ind(k-1)+1:ind(k)-1)); end Imp(6) = str2num(tline(ind(6):end)); fwrite(fid1,Imp(1),'short'); fwrite(fid2,Imp(2),'short'); fwrite(fid3,Imp(3),'short'); fwrite(fid4,Imp(4),'short'); fwrite(fid5,Imp(5),'short'); fwrite(fid6,Imp(6),'short'); end fclose(fid); fclose(fid1); fclose(fid2);fclose(fid3); fclose(fid4);fclose(fid5); fclose(fid6);fclose(fid0);
Il suffit simplement d'entrer en haut le nom du fichier csv à lire, en l'occurence test.csv ici. Mais cela ne marche pas et j'ai l'erreur classique In an assignment A(I) = B, the number of elements in B and I must be the same. mais je n'arrive pas à résoudre le problème. En fait le programme s'exécute mais il ne lit pas tout le fichier :
Vous trouverez le csv en pièce-jointe.ame= , test channels= , 13 sf= , 1.000, 50.000, 1.000, 50.000, 1.000, 50.000, 1.000, 50.000, 1.000, 50.000, 1.000, 50.000, 1.000 Types= , pH, Imp, Base, Imp, Base, Imp, Base, Imp, Base, Imp, Base, Imp, Base sf file= , 1.000 Num = 1 , 6.80, 1084.00, 812.00, 1014.00, 1134.00, 1617.00, 1384.00, 1282.00, 1524.00, 1461.00, 1805.00, 1136.00, 2064.00 ??? In an assignment A(I) = B, the number of elements in B and I must be the same. Error in ==> lecture_impedance at 30 Imp(6) = str2num(tline(ind(6):end));
Partager