MATLAB Answers

Output with specific critiria in data ?

2 views (last 30 days)
Ivan Mich
Ivan Mich on 7 Feb 2021
Commented: Walter Roberson on 21 Feb 2021
I am having a txt file with 4 columns. I would like to get a new file with spesific critiria, depending on the limits of values of 1st and 2nd columns. I would like my first column to have values ranging from a (minimum value) to b (maximum value). Also I would like my 2nd column to gave values ranging from c (minimum value) to d (maximum value). After that I want to get a file that would have all the rows that will have a<1st column values<b & c<2nd column values<d.
I am uploading a file as an example. (For example I would like to include values that:
2<1st column<18
30<2nd column<100)
Could you help me?
Thank you in advance
Ivan Mich
Ivan Mich on 21 Feb 2021
Excuse me but in my output file , only the tex are shown! The data (I mean numbers) are not shown. Specifically NaN is shown.
Could you help me to fix it?

Sign in to comment.

Answers (1)

Walter Roberson
Walter Roberson on 21 Feb 2021
%need some numbers to test with
a = 3; b = 20;
c = 5; d = 100;
%okay, do the work
filename1 = 'big.txt'; %arxeio me makroseismika
T = readtable(filename1, 'readvariablenames', false);
n = T{:,4};
m = T{:,5};
%a, b are numbers
mask = a<n & n<b & c<m & m<d;
selected = T(mask,:);
writetable(selected, 'OutputFile.xlsx', 'writevariablenames', false);
Walter Roberson
Walter Roberson on 21 Feb 2021
please post your a b c d values so that I can replicate the problem. To confirm, you are still using the same big.txt file you posted?

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!