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

8 views (last 30 days)
Mariana on 7 Dec 2019
Commented: Turlough Hughes on 8 Dec 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 CommentsShowHide 1 older comment
Mariana on 7 Dec 2019
Yes, I want to save all rows with values higher than 0.5 with a different name everytime I find them again.

Pandiyaraj Gnanasekar on 7 Dec 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.
Mariana on 7 Dec 2019
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....

Turlough Hughes on 7 Dec 2019
Edited: Turlough Hughes on 7 Dec 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
Turlough Hughes on 8 Dec 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.

Pandiyaraj Gnanasekar on 7 Dec 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.

### Categories

Find more on Numeric Types 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!

Translated by