Opening and editing text file

I need to use "importdata" to run a script, but my file has more columns at the bottom than at the top (like this:
Example1
2 2 3 2
2 2 1 1
1 0
2 4
1 1 2 200000 80000
it starts with 4 columns, and ends with 5), so when I use importdata, it makes a matrix with 4 columns, damaging my file. What I wanted to do is add any number at the end of the first data row (or second text row), preferentially a 0, to make it read my file as a 5-column matrix, like this:
Example1
2 2 3 2 0
2 2 1 1 0
1 0 0 0 0
2 4 0 0 0
1 1 2 200000 80000
(The zeros in the other columns are, as I understand, the result of the "importdata" in a 5-column matrix, I don't need to write them too.)
How can I do it?
Thanks a lot in advance!

댓글 수: 1

Image Analyst
Image Analyst 2013년 6월 22일
Do you know in advance the maximum number of columns that there should be?

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

답변 (1개)

Sean de Wolski
Sean de Wolski 2014년 6월 25일
편집: Sean de Wolski 2014년 6월 25일

0 개 추천

If you have R2012b or newer, just use the Import Tool to do the work for you. Right click on the file and select "Import Data". Make the selections and set that you want 0 for unimportable cells and then import. To automate it, under the import checkbox generate a script or a function to repeat the steps you did interactively.

카테고리

질문:

2013년 6월 22일

편집:

2014년 6월 25일

Community Treasure Hunt

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

Start Hunting!

Translated by