Filtering a matrix via User Input
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaires
Mohammad Sami
le 1 Avr 2020
Modifié(e) : Mohammad Sami
le 1 Avr 2020
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,:) = [];
Réponses (0)
Voir également
Catégories
En savoir plus sur Matched Filter and Ambiguity Function dans Help Center et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!