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

To resolve issues starting MATLAB on Mac OS X 10.10 (Yosemite) visit: http://www.mathworks.com/matlabcentral/answers/159016

How to remove content from file

Asked by Lalit Patil on 4 Dec 2012

http://speedy.sh/uC73Z/merged.txt

In this text file there are two columns. In second column i want to remove all those rows which falls between 279 to 291. So, how to do it..?

0 Comments

Lalit Patil

Products

No products are associated with this question.

1 Answer

Answer by Walter Roberson on 4 Dec 2012
YourData = load('merged.txt');
YourData(YourData(:,2) > 279 & YourData(:,2) < 291, :) = [];
save('Newmerged.txt', 'YourData', '-ascii');

Note that I have interpreted "between" as meaning not equal to 279 or 291 exactly, the open interval (279,291), rather than the closed interval [279, 291]

2 Comments

Lalit Patil on 4 Dec 2012

But, in this new generated text file how can i know which second column data corresponds to which first column data..?

Here two columns are generated, so, can't identify sequence..

So, i want same format of text file which was in merged.txt only need to remove data from range (279,291) and its corresponding first columns data's row..

Walter Roberson on 4 Dec 2012

The above code removes all rows in which the second column is in (279,291), producing an output file which has two columns, with each row being one of the original rows.

If you just wanted to remove items from the second column leaving the first column entirely in place, then you would end up with a second column which was shorter than the first column, and MATLAB cannot store numeric arrays which do not have equal number of values in the columns.

I'm wondering if you are trying to exclude data in that range, or if what you want is only the data in that range?

Walter Roberson

Contact us