1
votes

How can I get the numeric values in a column (let's say column 10) when the numeric values in another column (let's say column 9) are equal to a specific number and plot this in a graph.

e.g., When values of column 9 == 4, get the corresponding value of column 10 and plot. I am using row index number as a marker for time.

I am plotting all of column 10 to get a waveform then I want to use the data of column 9 to add markers to my waveform that are representative of a command occurring at a certain point in time.

Here is my code:

E = csvread('Experiment_at_10_45_1.csv');
[signal_rows, signal_columns] = size(E);
t=(1:signal_rows)/128; %128 samples per second

%% SNR plot for down frequency
plot(t,E(:,13),'k')

I hope my explanation is clear, as I have attempted to use a minimum working example of my code for the first time.

1
The point of a minimal reproducible example is so users can reproduce the issue with only what is provided in the question. Your example has a dependence on 'Experiment_at_10_45_1.csv', which nobody but you has. In the meantime I suggest taking a look at logical indexing and also What Every Computer Scientist Should Know About Floating-Point Arithmetic - excaza

1 Answers

1
votes

You'll want to use logical indexing to do this. You want to first create an array of 0 (false) and 1 (true) values where column 9 is equal to the value you want.

bool = E(:,9) == 4;

Then you'll want to use this 0 and 1 array as the row index. This will grab only the rows where column 9 was equal to 4. This is referred to as logical indexing.

E(bool, 10)

Then you can plot this

plot(t(bool), E(bool, 10))

As pointed out though, it is possible that the values aren't exactly to 4 due to floating point representation. To get around this, you just want to check if they are "close enough" using a very small epsilon.

bool = abs(E(:,9) - 4) < 1e-12;