1

I have a CSV file that has 3 columns having : String type(This can be a word or a sentence), integer type, integer type [these are the column types]
Now I want to store this data into a matrix,where the string(the whole sentence is stored into one cell)and the integers in one cell each too. I tried this:

fileID=fopen('training.csv');
C=textscan(fileID,'%s %d %d');

But it gives each word of the sentence in a different cell!The whole sentecne should be stored in one cell.How do I do that?

Thank you.

EDIT:It does seem to read anything now,this is what I get

celldisp(C)

C{1}{1} =

     jdl 

C{2} =

     []   

C{3} =

     []

EDIT:

jdl h-yf u ghjktnfhcrjuj hjcljd-yf-ljye                 129771  196
EAS CJDTNCRBH YFIRJHNJCNFY UJH HTDL HTCG                819100  458
rcfcyjzcrjuj rfycrf u rhfz edl                          547653  677
trfcthbyyehuf h-yt jnltkjv eavc xrfkjdcrjv u hjccbb d   970121  884
H-YF TRFNTHBYYEHUF U EDL XRFKJDCRJUJ                    938870  630
jdl yfhyfek h-yf rtktpyjljhjryjuj                       525855  598
rhfcyjzhcrf eghfdktybtv dyenhtyybq hfqjyf u ktybycrjuj  709215  403

Pretty much looks like this.It has 3500 rows of data

0

2 Answers 2

1

You could put the strings into quotation marks and then use %q in textscan:

%q  String, where double quotation marks indicate text to keep together

EDIT: If you only need to do that once (and not automatically via script in another process), what about manually importing the data from the CSV-File into MATLAB (via the import-tool provided by matlab:

enter image description here)

and then maybe save the imported variables simply to a MAT-file so you can access it easier in the future!?

Sign up to request clarification or add additional context in comments.

7 Comments

coukd you elaborate,I dont undertsand what you are saying.Should I modify the file I have? the file has 1000 rows.
Yeah what I meant was to export the data into a csv-file where the strings are between quotation marks, e.g. look like something like this: "bla bla bla";1;2 and then you could use the parameter %q in textscan to match the strings inbetween quotation marks. But that would only be an option if you could modify the csv-file easily (e.g. by changing the output routine of the program which outputs the csv-file). Where does the csv-file come from (generated from what)?
Given by my university.Its a training data i need to import into matlab to work on(Machine learning).It has 3 columuns and many many rows.The first column has a sentence.And im stuck wondering how i can import that first column as a first column in a matrix in matlab.
Oh okay then it's probably not easily possible to convert the format. So this solution isn't for you. Could you upload the csv-file?
If you'd want to always import the sama data within your trainig script, I sugest to manually import it once and save the imported data to a mat-file which you can easily load in MATLAB via load('bla.mat').
|
0

If you have Excel, you can use xlsread. You can also try importdata.

1 Comment

I dont have office.I have a mac

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.