필터 지우기
필터 지우기

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

조회 수: 8 (최근 30일)
Mariana
Mariana 2019년 12월 7일
댓글: Turlough Hughes 2019년 12월 8일
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
Turlough Hughes
Turlough Hughes 2019년 12월 7일
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 2019년 12월 7일
Yes, I want to save all rows with values higher than 0.5 with a different name everytime I find them again.

댓글을 달려면 로그인하십시오.

답변 (3개)

Pandiyaraj Gnanasekar
Pandiyaraj Gnanasekar 2019년 12월 7일
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
Mariana
Mariana 2019년 12월 7일
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....

댓글을 달려면 로그인하십시오.


Turlough Hughes
Turlough Hughes 2019년 12월 7일
편집: Turlough Hughes 2019년 12월 7일
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
Mariana
Mariana 2019년 12월 7일
편집: Mariana 2019년 12월 7일
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 2019년 12월 8일
"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
Pandiyaraj Gnanasekar 2019년 12월 7일
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.

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by