How to delete more than one point from data array in loop?
4 views (last 30 days)
Show older comments
I have written the following bit to avoid plotting a wrong measurement, from an array of measurements. For the 3 different data arrays, the plot should give me 3 different lines, one for each array.
I have written the code so that I can erase an incorrect data point for each data array, which has worked so far, but currently one of the arrays (the middle one) has 3 incorrect measurements and I want to erase these from my data before plotting it again.
The way I have written this code allows me to only take one data point from a single array. How can I delete more than one data point per array? Can this be done by using the hold on function? (I have tried plotting the array using the hold on function and by changing the number of the data point that I wish to delete, but it doesn't seem to be working).
data = [file1, file2, file3]; %the 3 array files
num = [0, 243, 245]; %the points I want to delete corresponding to the array in sample.
%I want to delete the data point (243, 244 and 245) from file2 but I don't
%know how.
for x = 1: length(data)
if num(x) ~= 0 %if there is an error data point, delete it from array
for i = 1:(num(x)-1)
a(i)=data(x).impulse(i);
end
for i=(num(x)+1):length(data(x).impulse)
a(i-1)=data(x).impulse(i);
end
elseif num(x) == 0 %if 0 there is nothing to delete and plot as is
for i = 1:length(data(x).impulse)
a(i)=data(x).impulse(i);
end
end
data(x).impulse=a
end
figure(2) %plotting the figure holding the 3 arrays into a single plot
for x = 1:length(sample)
plot(data(x).impulse , '-' )
hold on
end
0 Comments
Answers (1)
Sulaymon Eshkabilov
on 31 Jan 2022
If understood your question and you want to delete specific data rows, then you had better step your code somewhat in this manner:
% You want to delete the data points in 243, 244 and 245)
data(243:245).impulse = [];
% then Plot the resto of the data
for jj = 1:length(data)
plot(data(jj).impulse , '-' )
hold on
end
See Also
Categories
Find more on 2-D and 3-D Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!