How to delete more than one point from data array in loop?

19 visualizaciones (últimos 30 días)
Goncalo Costa
Goncalo Costa el 30 de En. de 2022
Editada: Goncalo Costa el 31 de En. de 2022
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

Respuestas (1)

Sulaymon Eshkabilov
Sulaymon Eshkabilov el 31 de En. de 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
  1 comentario
Goncalo Costa
Goncalo Costa el 31 de En. de 2022
Thank you for your help.
I have tried to do this for a different file where I only care for a data column in the whole array, but this does not seem to work. For example, when I want to delete the 96th data point from the 60th column of the the 3rd data array, I write this down.
data(3).n(96, 60) = [];
But I get the message:
"A null assignment can have only one non-colon index."
I don't see how, as this is pretty much the same thing as what you wrote above. Is it not?
When use these data array, the section above where I wrote:
data(x).impulse=a
became:
data(x).n(:, 60)=a
Thank you so much for your help.

Iniciar sesión para comentar.

Community Treasure Hunt

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

Start Hunting!

Translated by