필터 지우기
필터 지우기

Filtering a matrix via User Input

조회 수: 1 (최근 30일)
MILLER BIGGELAAR
MILLER BIGGELAAR 2020년 4월 1일
댓글: MILLER BIGGELAAR 2020년 4월 1일
Hi guys,
I am trying to create a program that will get the user to select a file and then using the inputdlg command, select a specific set of a filters, then the program will plot the file (in this case 3 columns each with x amount of rows) but filter out the data the user has specified (eg. filtering the min and max limit of column 1 will delete the row corresponding and so on for each column).
[file,path] = uigetfile('*.txt');
if isequal(file,0)
disp('User has selected Cancel.');
else
disp(['User has selected ', fullfile(file)]);
end
Data = readmatrix(file);
Filtering_q = {'Enter Easting Filtering Minimum (m)',...
'Enter Easting Filtering Maximum (m)',...
'Enter Northing Filtering Minimum (m)',...
'Enter Northing Filtering Maximum (m)'};
Filterlims = inputdlg(Filtering_q);
Eastingmin = str2num(Filterlims{1});
Eastingmax = str2num(Filterlims{2});
Northingmin = str2num(Filterlims{3});
Northingmax = str2num(Filterlims{4});
rows_to_delete_Eastingmin = find(Data(:,1)<Eastingmin);
rows_to_delete_Eastingmax = find(Data(:,1)>Eastingmax);
rows_to_delete_Northingmin = find(Data(:,2)<Northingmin);
rows_to_delete_Northingmax = find(Data(:,2)>Northingmax);
Data((rows_to_delete_Eastingmin):(rows_to_delete_Eastingmax):(rows_to_delete_Northingmin):(rows_to_delete_Northingmax),:) = [];
E = Data(:,1);
N = Data(:,2);
D = Data(:,3);
plot3(E, N, D, '.')
This is what I have so far and everything besides the filtering works.
I am using MATLAB 2019a.
  댓글 수: 2
Mohammad Sami
Mohammad Sami 2020년 4월 1일
편집: Mohammad Sami 2020년 4월 1일
You can use OR '|' or AND '&' to combine your logical statements. you don't need to use find as matlab works directly with logical indexes.
rows_to_delete_Eastingmin = Data(:,1)<Eastingmin;
rows_to_delete_Eastingmax = Data(:,1)>Eastingmax;
rows_to_delete_Northingmin = Data(:,2)<Northingmin;
rows_to_delete_Northingmax = Data(:,2)>Northingmax;
r_del = rows_to_delete_Eastingmin | rows_to_delete_Eastingmax | rows_to_delete_Northingmin | rows_to_delete_Northingmax;
Data(r_del,:) = [];
MILLER BIGGELAAR
MILLER BIGGELAAR 2020년 4월 1일
Thank you but after running both OR | and the AND & command it hasn't actually filtered the numbers out of the Data matrix. Any more suggestions?

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

Help CenterFile Exchange에서 Matched Filter and Ambiguity Function에 대해 자세히 알아보기

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by