필터 지우기
필터 지우기

Info

이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.

How to add new rows to text file with missing data?

조회 수: 1 (최근 30일)
Cameron Spooner
Cameron Spooner 2016년 7월 4일
마감: MATLAB Answer Bot 2021년 8월 20일
I have a txt file containing 4 tab delineated columns that are missing rows, like;
1, x, y, z
2, x, y, z
5, x, y, z
I am trying to write a script that will add the missing rows with the correct missing integer in the first column and and assign a 0 value to the other 3 columns, like;
1, x, y, z
2, x, y, z
3, 0, 0, 0
4, 0, 0, 0
5, x, y, z
What would be the easiest way to go about doing this?
  댓글 수: 2
per isakson
per isakson 2016년 7월 4일
Does the entire file fit comfortably in memory (RAM)?

답변 (1개)

Azzi Abdelmalek
Azzi Abdelmalek 2016년 7월 4일
s=importdata('fic.txt')
out=zeros(s(end,1),4)
out(s(:,1),:)=s

이 질문은 마감되었습니다.

제품

Community Treasure Hunt

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

Start Hunting!

Translated by