Bonjour
j'ai une base de donnée que je vais utilisé dans matlab.
Je l'ai sur un fichier .txt ert je veux utiliser la fonction load Car cette base contient les entrées et les sorties que j'ai besoin.
Comment faire?
Version imprimable
Bonjour
j'ai une base de donnée que je vais utilisé dans matlab.
Je l'ai sur un fichier .txt ert je veux utiliser la fonction load Car cette base contient les entrées et les sorties que j'ai besoin.
Comment faire?
Bonjour,
- Quel est le format de ton fichier texte?
- As-tu essayé d'utiliser la fonction LOAD (comme indiqué dans l'aide correspondante)?
Sinon tu peux utiliser les fonctions TEXTSCAN, TEXTREAD...
Bonne apm,
Duf
Bonjour,
Il veut utiliser la fonction "load"
La commande est la suivante si ton fichier "filename.txt" se trouve dans le répertoire courant :ChristopheCode:load filename.txt
Il sera toujours plus efficace de spécifier le format du fichier avec LOAD :
Code:load('filename.txt','-ascii')
Si tu fais un edit de la fonction "LOAD" tu obtiens ceci où tu peux lire que si l'extension spécifiée est différent de ".mat" alors il utilise le mode ascii...
Maintenant, en spécifiant toi-même, tu es sûr de ce que tu fais...Code:
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
43
44
45
46
47
48
49
50
51
52 %LOAD Load workspace variables from disk. % LOAD FILENAME retrieves all variables from a file given a full pathname % or a MATLABPATH relative partial pathname (see PARTIALPATH). If % FILENAME has no extension LOAD looks for FILENAME.mat and, if found, % LOAD treats the file as a binary "MAT-file". If FILENAME.mat is not % found, or if FILENAME has an extension other than .mat it is treated as % an ASCII file. % % LOAD, by itself, uses the binary "MAT-file" named 'matlab.mat'. It is % an error if 'matlab.mat' is not found. % % LOAD FILENAME X loads only X. % LOAD FILENAME X Y Z ... loads just the specified variables. The % wildcard '*' loads variables that match a pattern (MAT-file only). % % LOAD FILENAME -REGEXP PAT1 PAT2 can be used to load all variables % matching the specified patterns using regular expressions. For more % information on using regular expressions, type "doc regexp" at the % command prompt. % % LOAD -ASCII FILENAME or LOAD -MAT FILENAME forces LOAD to treat the % file as either an ASCII file or a MAT-file regardless of file % extension. With -ASCII, LOAD will error if the file is not numeric % text. With -MAT, LOAD will error if the file is not a MAT-file % generated by SAVE -MAT. % % If FILENAME is a MAT-file, requested variables from FILENAME are % created in the workspace. If FILENAME is not a MAT-file, a double % precision array is created with name based on FILENAME. Leading % underscores or digits in FILENAME are replaced with X. Other non-alpha % chars in FILENAME are replaced with underscores. % % S = LOAD(...) returns the contents of FILENAME in variable S. If % FILENAME is a MAT-file, S is a struct containing fields matching the % variables retrieved. If FILENAME is an ASCII file, S is a double % precision array. % % Examples for pattern matching: % load fname a* % Load variables starting with "a" % load fname -regexp \d % Load variables containing any digits % % Examples for specifying filename and variables: % load mydata.mat v1 % Use with literal filename % load 'my data file.mat' v1 % Use when filename has spaces % d = load('mydata.mat', 'v1') % Use when output is specified % load(savefile, 'v1') % Use when filename is stored in a variable % % See also SAVE, WHOS, REGEXP, UILOAD, SPCONVERT, PARTIALPATH, IOFUN, FILEFORMATS. % Copyright 1984-2006 The MathWorks, Inc. % $Revision: 5.27.4.5 $ $Date: 2006/05/05 15:55:59 $ % Built-in function.
Christophe
Tu as bien entendu parfaitement raison, mais...
Mieux que ça, tu évites que la détection automatique du format par MATLAB échoue (ça arrive) et tu accélères la lecture car les tests de détection ne sont plus effectués par MATLAB.
C'est la même chose avec IMREAD par exemple.
fonctionne parfaitement, mais :Code:X = imread('test.jpg');
est meilleur.Code:X = imread('test.jpg','jpg');