Filtering data from a table. How can I save values that are higher that 0.5?

10 vues (au cours des 30 derniers jours)
Mariana
Mariana le 7 Déc 2019
Commenté : Turlough Hughes le 8 Déc 2019
I can't find a solution to my problem. I have data stored in a table. This data represent the behavior of a signal in time.
I want to create a program that reads each row of a table if a value on a specific column is 0 do not save, but if the value is higher start saving.
Example:
0 0 0 0 0 1 1.2 1.5 1.6 1.3 1 0 0 0 0 0 0 0 0 2 2.4 5 3 2 0 0 0 0 0 0 0 0 0 0 . . . . . . . . . .
--------------- save 1 ------------------- save 2 -------------------------
Code:
b=a(:,4) %column to search
rate=length(b) %number of rows
for i=1:rate
b1 = b(i); % read value of row
if b1 < 0.5
end
if b1 > 0.5
end
end
*I have an overwrite problem
Hope you can help me. Thanks.
  2 commentaires
Turlough Hughes
Turlough Hughes le 7 Déc 2019
It would be helpful to attach your variable as ".mat", also are you looking to save all rows of a based on a(:,4)?
Mariana
Mariana le 7 Déc 2019
Yes, I want to save all rows with values higher than 0.5 with a different name everytime I find them again.

Connectez-vous pour commenter.

Réponses (3)

Pandiyaraj Gnanasekar
Pandiyaraj Gnanasekar le 7 Déc 2019
Hi Mariana Gutierrez,
b = a ( : , 4 ); %column to search
rate = length(b); %number of rows
V = zeros(rate,1);
for i =1:rate
if b(i) > 0.5
V(i) = b(i);
end
end
I think this might help! Try this or explain a bit more in next comment.
  1 commentaire
Mariana
Mariana le 7 Déc 2019
a = xlsread(filename)
b = a ( : , 4 ); %column to search
rate = length(b); %number of rows
V = zeros(rate,1);
for i =1:rate
if b(i) > 0.5
V(i) = b(i);
end
end
*I tried this, but it saves the same values of b. I dont understand why. It suppose to just save values higher than 0.5....

Connectez-vous pour commenter.


Turlough Hughes
Turlough Hughes le 7 Déc 2019
Modifié(e) : Turlough Hughes le 7 Déc 2019
You could get an index for each chunk of data as follows:
idx=find(a(:,4)>0.5)
idx2=find((idx(2:end)-idx(1:end-1))~=1);
idx2=unique(sort([min(idx); idx(idx2); idx(idx2+1); max(idx)])); % this is the start and end of each chunk of data.
Then to store data like this you would typically put it into a cell array:
for c=1:length(idx2)/2
data{c,1}=a(idx2(2*c-1):idx2(2*c),:);
end
EDIT: As per comments below
  6 commentaires
Mariana
Mariana le 7 Déc 2019
Modifié(e) : Mariana le 7 Déc 2019
Data1 and Data2 have values of 0 and also higher ones. I thinks is not filtering correctly.
This what I am trying:
a = xlsread(filename)
t = a( : , 1) : %time value
b = a ( : , 4 ); %column to search
c = find (b <= 0.5) %row numbers
values_c= a(c,:) %create a new variable with values lower than 0.5
d = find (b <= 0.5) %row numbers
values_d= a(d,:) %create a new variable with values higher than 0.5
rate = length (values_d)
for i =1:rate
j = i + 1:
t1 = values_d(i,1)
t2 = values_d(j,1)
diff = t2 - t1
if diff > 5
stop(i) = values_d(i);
end
end
change = find(stop ~= );
l = length(change)
Basically, what I am doing is to find all zero values save them in a table and in other table save non zero values.
Then from (values_d higuer than 0.5) I read the column 1 which represents the time if the time difference is higher than 5 seconds it is because a series of 0 happened in between. In other words I should cut it and save with different name every time a find a time gap higher than 5.
Turlough Hughes
Turlough Hughes le 8 Déc 2019
"I tried it , but is not working it also saves 0 values"
I subsequently edited my answer. There was a problem with the indexing but it should be fine now.

Connectez-vous pour commenter.


Pandiyaraj Gnanasekar
Pandiyaraj Gnanasekar le 7 Déc 2019
Hi Mariana Gutierrez,
If you want only the values greater than 0.5 and not the zeros. You can simply remove those zeros from the vector b.
try this,
b = a ( : , 4 );
b(b==0) = []; % this will remove values equal to zeros from b vector.
Hope it will solve your problem.

Catégories

En savoir plus sur Logical dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by