0

im new to matlab and coding. I have a csv file with data that goes like:

3 2 91 83 17

3 2 86 84 4

3 2 90 83 162

(there's a total of 7000 rows)

I need a way to read this into an array, can the array be something like A[I,J,K,L,M] with age=I for example? How would i go about doing this?

2
  • 3
    See dlmread. Commented Oct 11, 2014 at 17:03
  • Say I created an array like [age, Doa, los, gender, dest]. Would there be a way to get data in the first coloum in age, data in the second coloum into DOA etc? Commented Oct 11, 2014 at 20:10

2 Answers 2

1
M = csvread(filename);
age = M(:,1); Doa = M(:,2); los = M(:,3); gender = M(:,4); dest = M(:,5);
Sign up to request clarification or add additional context in comments.

3 Comments

Thank you for your answer it helped a lot. Im running into an error now though, i have my code as: M = csvread('peterdatnew.csv', 1,0); M(:,1) = dest; M(:,2) = gen; M(:,3) = age; M(:,4) = year; M(:,5) = dur; and i get the error: Undefined function or variable 'dest'. i tried dest = 0; gen = 0; but that literally set the value to 0. How should i go about resolving this?
Sorry, was typing it too quickly, just swap lhs and rhs (see corrected answer)
Great, you're welcome :). Would you mind accepting an answer to mark it closed, see here meta.stackexchange.com/questions/5234/…
0

dlmread(), csvread(), and xlsread() all work well.

Note that the first two (dlmread and csvread) are for numeric data only, and xlsread is limited by what excel can process (which in my experience is capped at somewhere around 1 million rows). xlsread can get you text and raw as well.

Comments

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.