MATLAB Answers


how to do zero padding in middle

Asked by Lalit Patil on 21 Nov 2012

I have some text files.. All text file contains two columns. both of 480 rows. But some text files have some rows missing.. In one of them after 63rd row directly there is 86th row.. So, total rows get reduced to 450. Now i want to convert this rows in again 480rows by zero padding from 64th to 85th.. So, how to do..? This text file is attached here..


Norton won't let me:

Malicious Web Site Blocked

You attempted to access:

This is a known malicious web site. It is recommended that you do NOT visit this site. The detailed report explains the security risks on this site.

For your protection, this web site has been blocked. Visit Symantec to learn more about phishing and internet security.

Threat Report

Total threats found: 1

Drive-By Downloads (what's this?)

Threats found: 1 Here is a complete list: (for more information about a specific threat, click on the Threat Name below) Threat Name: Malicious Site: Malicious Domain Request 2 Location: <>

Ok..Is there any other way to upload my text file here..! or if you know any other site..


No products are associated with this question.

1 Answer

Answer by Walter Roberson
on 21 Nov 2012

Consider using textscan() with the MissingValue option set to 0


If i do B = 1:480; B = B'; firstcolumn = [1 ;2 ;3;..63; ;86;...480]; missingvalues = setdiff(B,firstcolumn);

then i will get all the missing points.. Now how to add this points at last in first column in text file and then to set its corresponding value to 0...

If the values can go at the end then if M is what you read the data in to,

M(end+1:end+length(missingvalues), 1) = missingvalues;

and then write the file out in an appropriate format.

I got solution.. First i find missing values then stored it in another text file, then merged both files.. so, i got total 480 rows... Thanks for help..!

Join the 15-year community celebration.

Play games and win prizes!

Learn more
Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

MATLAB Academy

New to MATLAB?

Learn MATLAB today!