Calculating Average in Google doc based on values in other columns - average

I want to calculate the average marks obtained by students of set1, set2 and set3. Is there any way to do this.

The function you're looking for is averageif. If your two columns are A and B, and you have 10 rows:
=AVERAGEIF(A1:A10,"Set 1",B1:B10)
=AVERAGEIF(A1:A10,"Set 2",B1:B10)
=AVERAGEIF(A1:A10,"Set 3",B1:B10)

Related

Large dataset, how to select a particular range

I have a dataset that consists of 30000 rows and 48 columns, and I wish to select rows 1:24100 for columns 1:3, 5 and 8:10. How can I do that?
Thank you!
Using matrix indexing, you give give the row indices first, and then the column indices. These indices can be vectors.
data = rand(30000,48);
selection = data(1:24100, [1:3 5 8:10])

How to do the mean with specific conditions from a table? matlab

So I am trying to get the mean/sum of cyclists on different bikeways when there is rainfall.
table of bikeways and the conditions
How would I try and get the mean of each column of bikeways when rainfall > 1?
Thanks
The documentation for accessing data in a table is very helpful for this. For a given column/variable var, you can get the mean when the rainfall is greater than 1 like so:
meanValue = mean(combined_data.var(combined_data.rainfall > 1));
If you'd like to compute the means for a number of columns at once, such as for the first 26 columns, you can do this:
meanValues = mean(combined_data{combined_data.rainfall > 1, 1:26});
And meanValues will be a 1-by-26 row vector of mean values for each column.

How to plot numeric values in a column when values in another column are equal to specific number

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.
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;

calculate the number of pixel in a row and column

I get an image, let say
img=imread('test.jpg')
how can I count all pixel values in each row for a projection on a 1D signal to the right and the pixel values of each column for a projection to the bottom.
does it mean I need to find sum or the pixel in row and column.
what is the statement to sum row pixel and column pixel?
is this statement for sum of row pixel : sum_all = sum(img(:)); if so, what is the statement for sum of column pixel?
you should check the documentation for the sum function in matlab. The second argument specifies the dimension to sum. if dimension=1, then you're summing the rows. If dimension=2, then you want to sum the columns. Therefore, you have the simple code:
% Sum the rows
sum_rows = sum(img);
% Alternate form to sum the rows
sum_rows = sum(img, 1);
% sum the columns
sum_cols = sum(img, 2);
You can slice an n-dimensional array using the img(:,x) notation. the : indicates that you want all of the indexes from that pixel. You could also do img(a:b,x) if you want a subset of one row.
Using this method, you can sum one row of an image as sum(img(:,n)) where n is the row you want to sum. Likewise, for columns, it would be sum(img(n,:)).
I have done the following:
img=imread('test4.jpg');
sum_row = sum(img,2);
this gives me the sum for every row,,,
sum_col = sum(img,1);
this gives me the sum for every column,,,
is that correct?
Yes I got it correct,
so let say i have 2 values here at the end,
what does it mean by If there are periodic highs or lows?

Extracting row and column names for matrix elements with a particular value?

I have two matrices relating to a list of 347 stocks. The remainingTickers matrix is 347*1 and contains stock symbol names. The GMAT matrix is 347*347 and contains 0 or 1 entries that indicate whether a pair of stocks have a correlation greater than 0.5.
I want to create a new matrix with two columns that consist of the pair of stock symbol names corresponding to the row and column for each 1 value in GMAT. How can I do this?
I think you might need something like:
[i, j] = find(GMAT);
left = [remainingTickers(i)];
right = [remainingTickers(j)];
left{k} and right{k} will form a pair that is correlated for any value of k.
[a b] = find(gmat==1);
and eight more characters