- read the file as characters
- remove all '"'
- parse the character string with textscan
Importing from Openoffice
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
The csv (or xls) file is a list of numbers but when i import it shows a list of numbers in quotes "234" "432" etc
and im not able to import them as numbers. Only way is to import as a cell array but then i cant use them as numbers in matlab and i cant convert them to numbers.
0 Commenti
Risposte (5)
per isakson
il 7 Giu 2012
CSV comes in different flavors and Microsoft make their own rules. Google "CSV file format" and see for example Common Format and MIME Type for Comma-Separated Values (CSV) Files. I guess OpenOffice tries to honor the "standard".
It seems Matlab has no obvious way to read proper CSV files.
A brute approach is to
Something like
function M = Answer( )
fid = fopen( 'cssm.txt', 'r' );
str = fread( fid, '*char' );
sts = fclose( fid );
str( str == '"' ) = [];
cac = textscan( str, format );
peel off the braces
end
This will certainly not work in all cases
CapaB
il 8 Giu 2012
2 Commenti
per isakson
il 8 Giu 2012
It's hard to guess what's going on! What does str(1:120)' display?
"(Error using fread Invalid file identifier.)" hints that you fail to open the file. However, you say you read "4630x1 cell".
Why use cell2mat?
per isakson
il 9 Giu 2012
.
"commas instead of dots" is definately a problem!
fid = fopen( 'HMhist.csv', 'r' );
str = fread( fid, '*char' );
sts = fclose( fid );
str( str == '"' ) = [];
str( str == ',' ) = '.';
cac = textscan( str, '%f' );
Why do you believe that the format, '%f', is appropriate? First you need to get the format right.
What does str(1:120)' display? Don't forget the blip! Or do
permute( str(1:124), [2,1] )
CapaB
il 10 Giu 2012
1 Commento
Walter Roberson
il 10 Giu 2012
I would suggest this should be a new Question as it has nothing to do with importing CVS
Vedere anche
Categorie
Scopri di più su Low-Level File I/O in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!