Help in importing csv file

1 Ansicht (letzte 30 Tage)
FRANCISCO
FRANCISCO am 11 Nov. 2013
Beantwortet: bethel o am 11 Nov. 2013
good, I have two problems:
1 - The first is that I want to import a csv file to matlab which has the following form:
0000,1,0.142857
0001,0,0
0010,0,0
0011,0,0
0100,0,0
0101,3,0.428571
0110,0,0
0111,0,0
1000,0,0
1001,0,0
1010,2,0.285714
1011,0,0
1100,0,0
The point is that I want to represent me digits according to the first comma are here, but when you import matlab represents me well:
0
1
10
11
100
101
110
111
1000
1001
1010
1011
1100
1101
2 - my second question is how I can do to make each of these numbers represent me in each column:
1101 ------------ | 1 | 1 | 0 | 1 |
thank you very much
  2 Kommentare
bethel o
bethel o am 11 Nov. 2013
I don't really understand your question. The use of 'me' is confusing. What is it?
Why don't you read the csv file yourself, Read the file line by line and split each line with
C = strsplit(str,',')
FRANCISCO
FRANCISCO am 11 Nov. 2013
I can not read the csv file from excel because it contains a lot of data in excel file not fully charged. Then load it into Matlab and I intend to make these operations to transform the data as I said above. When I use:
if true
% code
aaa = ImportData ('data.csv');
end
the file is read as follows:
0
1
10
11
100
101
110
111
1000
1001
1010
1011
1100
1101
and should read:
0000
0001
0010
0011
0100
0101
0110
0111
1000
1001
1010
1011
1100
and then I want is that each of these numbers is represented in a column in matlab:
0000 ----------- | 0 | 0 | 0 | 0 |

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Simon
Simon am 11 Nov. 2013
Bearbeitet: Simon am 11 Nov. 2013
Hi!
You may just load your file and process it afterwards like
% load file
fid = fopen('data.csv', 'r');
FC = textscan(fid, '%s', 'Delimiter', '\n');
fclose(fid);
FC = FC{1};
% extract data
for n = 1:length(FC)
Data{n, 1:3} = sscanf(FC{n}, '%s %d %f');
end
The format string depends on your data. If you use "%s", you will keep your first column as string '0000'. You can split this afterwards in 0|0|0|0.

Weitere Antworten (1)

bethel o
bethel o am 11 Nov. 2013
OK I was going to tell you what Simon already said. The full instructions can be found here Documentation

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by