loading a 2d matrix from a text file comes in as an array

I have two columns of data in a text file that I'm trying to read in using the load function. For some reason it is loading the file as a single array (1 x 1340) instead of a matrix (670 x 2). I am using the 2012a and I'm on a Mac.

댓글 수: 1

Just figured out that it doesn't like the format the data was saved in. I opened it in excel, then saved it as a windows text file, and it worked. Tab delimited did not work. Any thoughts on how to make it work without resaving all of my text files as windows text files?

댓글을 달려면 로그인하십시오.

답변 (1개)

Azzi Abdelmalek
Azzi Abdelmalek 2013년 2월 22일
If its loading as a single array, depending on the order of your data you can For example:
x y
1 10
2 20
3 30
If the data comes like
data=[1 2 3 10 20 30]
n=numel(data)
x=data(1:n/2)
y=data(n/2+1:end)
If data comes like
data=[1 10 2 20 3 30];
x=data(1:2:end);
y=data(2:2:end)

카테고리

질문:

2013년 2월 22일

Community Treasure Hunt

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

Start Hunting!

Translated by