I have a timetable with different variables corresponding to measurements made with an instrument. One of the variables is a logic variable, "Valve State" that indicates whether the measurement is meant for a background or is a sample measurement.
How could I iterate through the time table and find the most recent variable with "Valve State" == 1 and use that for the calculation on the next chunk of rows which have a "Valve State" == 0?

 Akzeptierte Antwort

Walter Roberson
Walter Roberson am 17 Feb. 2021

0 Stimmen

measurement(valve_state == 0) = nan;
fillmissing(measurement, 'previous')

3 Kommentare

Poison Idea fan
Poison Idea fan am 17 Feb. 2021
Bearbeitet: Poison Idea fan am 17 Feb. 2021
This works for how I wrote the question, but I wrote the question poorly. I don't need to get rid of the valve_state == 0 values, rather I need to take value(valve_state == 0) - value(valve_state == 1). The values are in a cycle where valve_state == 1 for 10 minutes and then it switches to valve_state == 0 for 30 minutes. When valve_state == 0 I need to use the most recent set of valve_state == 1 for the calculation.
I appreciate the quick response. I am new to Answers.
If you do
VSR = reshape(valve_state, 1, []); %need a row
mask = VSR == 0;
start0 = strfind([0 mask], [0 1]);
stop0 = strfind([mask 0], [1 0]);
Now start0(K) marks the start of a run of 0's and stop0(K) marks the end of the same run. Under the assumption that the first datapoint is a 1 rather than 0, you would use the datapoint at start0(K)-1 . So perhaps something like
basevalue = measurement;
if start0(1) == 1
basevalue(1:stop0(1)) = something; %this is the case where the valve started 0
start0(1) = []; stop0(1) = [];
end
for K = 1 : length(start0)
basevalue(start0(K):stop0(K)) = basevalue(start0(K)-1);
end
Poison Idea fan
Poison Idea fan am 17 Feb. 2021
This is very helpful thank you! I couldn't figure out a way to isolate the run of 0's and what not.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu MATLAB finden Sie in Hilfe-Center und File Exchange

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by