Info

此问题已关闭。 请重新打开它进行编辑或回答。

Import Data using function

1 次查看(过去 30 天)
Arvind Mahendran
Arvind Mahendran 2012-3-26
关闭: MATLAB Answer Bot 2021-8-20
I want to import 2 .DAT into my code using a function When using the import wizard i make it a point to neglect the textdata here is a small exert of the files
XAXIS ZAXIS Eintensity Hintensity Sintensity
-1.50000000 -1.50000000 1.04858450 0.88251762 0.96197417
-1.47000000 -1.50000000 1.05946741 0.90707882 0.98031650
-1.44000000 -1.50000000 0.98867187 1.03632028 1.01221574
-1.41000000 -1.50000000 0.98153259 1.06804583 1.02387586
-1.38000000 -1.50000000 0.96053362 1.05617225 1.00721842
-1.35000000 -1.50000000 0.99755509 1.01285533 1.00517610
-1.32000000 -1.50000000 0.99126668 1.04608833 1.01830865
-1.29000000 -1.50000000 1.02578740 0.98220775 1.00376109
-1.26000000 -1.50000000 1.08350872 0.85828860 0.96434599
-1.23000000 -1.50000000 1.09498790 0.88392760 0.98381402
i've tried to use the load function but the text at the top of the file creates an error. I cannot change the file as it is hardcoded into another software.
Any ideas?

回答(2 个)

Geoff
Geoff 2012-3-26
A = textread( 'mydata.dat', '', 'headerlines', 1 );

per isakson
per isakson 2012-3-26
Why not use the wizard and just ignore or delete textdata?
Here is an alternative to textread. Doc says: "textread will be removed in a future version. Use textscan instead."
I copied your sample to 'h:\m\cssm\cssm.dat'.
I prefer to give Headerlines the value 2. In case I redefine Whitespace. That is if there is an empty line between the header and the data.
fid = fopen( 'h:\m\cssm\cssm.dat', 'r' );
cac = textscan( fid, '', 'Headerlines', 2 );
fclose( fid );

此问题已关闭。

标签

Community Treasure Hunt

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

Start Hunting!

Translated by