Need help to delete garbage values from a Matrix
Afficher commentaires plus anciens
% Create the .dat file
clc
format short
tout1=tout;
tout2=tout;
r=size(tout1);
n=r(1,1);
for i=2:n
if mod(tout1(i)-tout1(i-1), 0.00005) ~= 0
%if(tout1 > )
if mod(tout1(i), 0.00005) ~= 0
tout1(i) = 0;
else
tout1(i+1) = 0;
end
end
end
tout1 = unique(tout1);
tout=tout1;
the above code is written to delete garbage values that are being generated in the a matrix TOUT when i insert display block in simulink. But it makes every third row zero when the above code is implemented. so instead of getting 20001 values from 20005, i am getting 13386 values whic generates error saying that the dimentions of the matrix are not consistant.
why is it deleting extra values which satify the condition in the first loop?
Will like some help please!!!!!!!
4 commentaires
Guillaume
le 6 Fév 2020
You've failed to explain what your definition of a garbage value is, and since your code is very bizarre and not commented, it's really not clear what it is.
Note that your code doesn't do any deletion unless you consider that taking the unique values of a vector is a deletion.
David Goodmanson
le 6 Fév 2020
Hi Tejas,
With the mod commands it looks like you may be using error-prone exact equality checks with floating point numbers.
Guillaume
le 6 Fév 2020
That's one of the many bizarre things about the code. Also the code appears to check that the difference between continuous numbers is a multiple of 0.00005 but later on that it's the numbers themselves that are multiple, which is a completely different thing. The difference between two numbers can be a multiple of 0.00005 without any of the numbers being a multiple.
Other bizarre thing, is that the difference is between index i and i-1 but it's i or i+1 that is later modified.
Tejas Rivonkar
le 6 Fév 2020
Modifié(e) : Tejas Rivonkar
le 6 Fév 2020
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur General Applications 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!