Remove negative numbers and rows from an array
Afficher commentaires plus anciens
Good afternoon,
What I want to do is to find and remove all negative values in the 2 column of each matrix within the array and its corrosponding row, leaving only the postive ones. The codes with I have used are unable to achieve this as there are always problems involving the exceedance of array bounds.
Could you help please?
%% Flume find peaks
[n,m] = size(flume);
data_flume = []; % WL is the final column
for i = 2:m %Excludes 1st column
[pks{i}, idx{i}] = findpeaks(flume(:,i));
data_flume{i}(:,1) = flume(idx{i});
data_flume{i}(:,2) = pks{i}(:);1; % Works to identify peaks and their locations
if isempty(data_flume{i});
data_flume{i} = NaN; % Column 26 will be blank as their are no peaks, this is to fill it in.
end
data_flume{i}([data_flume{:,2}]<0,:)=[] % Code will not remove negative values and their rows
end
%% Alterative code to remove negative values
for j = 1 : numel( data_flume )
data_flume_pos = data_flume{j}(:,2) < 0 ;
data_flume{j} = data_flume{j}(~data_flume_pos,:) ; % Or data_flume{j}(data_flume_pos,:) = [] ;
end
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Characters and Strings dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!