フィルターのクリア

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)?
Cameron Spooner
Cameron Spooner 2016 年 7 月 5 日
yes

回答 (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