finding the max value of every 24 rows in a matrix of a certain column - multiple-columns

I have imported a huge excel file into matlab. The file is a database with 5 columns and 175000 rows. I want the maximum value of every 24 rows of the third column.
can anyone help me plz?

I hope I got what you want right,
I believe you can do something like this:
(forgive me I'm not writing matlab coding)
col = 3
for i = 1 to number_of_rows
Add the element at (i, col) to a new array
i=i+23
end for
then fine the maximum value in the new array you created in the loop, hope this helps

Related

Find Row Where Sum is Reached from Single Joined Column (not a range of cells)

I'm trying to run a formula to identify in which row a total sum is reached.
I've been able to do that calculation when I have an entire range of cells to work with, however, I'm doing a filter / join calculation because I need to do this from an individual row with all the data instead of an entire range of cells.
Here is an example google sheet (EDITABLE - feel free) where you can see the range and working formula (both below). Help getting this from the single-cell versions on the top would be very helpful. The error I get with both row() & index() formulas is that the "argument must be a range".
If there's another way to do this besides the single-cell I had that doesn't require referencing the range (e.g. using FILTER) then I'm open to it.
My desired result is to be able to pull the get the second column (date) at the point when the sum is reached (can be via the INDEX & MATCH formula I used or an alternative). This will tell me the earliest date that feeds into the desired sum.
Yes unfortunately you can't do that trick with SUMIFS to get a running total unless the column being totalled is an actual range.
The only approach I know is to multiply successive values by a triangular array like this:
1 0 0 ...
1 1 0 ...
1 1 1 ...
so you get just the sum of the first value, the first 2 values, then 3 values up to n.
This is the formula in F5:
=ArrayFormula(match(E14,mmult(IF(ROW(A1:INDEX(A1:ALL1000,COUNT(split(A5,",")),COUNT(split(A5,","))))>=
COLUMN(A1:INDEX(A1:ALL1000,COUNT(split(A5,",")),COUNT(split(A5,",")))),1,0),TRANSPOSE(SPLIT(A5,",")))))
And the formula in F6 is just
=to_date(INDEX(TRANSPOSE(SPLIT(B5,",")),F5,1))
EDIT
You might have guessed that the above formula was adapted from Excel, where you try to avoid volatile functions like Offset and Indirect.
I have realised since posting this answer that it could be improved in two ways:
(1) By using Offset or Indirect, thus avoiding the need to define a range of arbitrary size like A1:ALL1000
(2) By implying a 2D array by comparing a row and column vector, rather than actually defining a 2D array. This would give you something like this in F5:
=ArrayFormula(match(E14,mmult(IF(ROW(indirect("A1:"&address(COUNT(split(A5,",")),1)))>=
COLUMN(indirect("A1:"&address(1,COUNT(split(A5,","))))),1,0),TRANSPOSE(SPLIT(A5,",")))))
which could be further simplified to:
=ArrayFormula(match(E14,mmult(IF(ROW(indirect("A1:A"&COUNT(split(A5,","))))>=
COLUMN(indirect("A1:"&address(1,COUNT(split(A5,","))))),1,0),TRANSPOSE(SPLIT(A5,",")))))

Google Sheets: Find Row In a Column That Last Had A Larger Value Than The Current Row

Updated: While the solution provided =IF(A2>A1,IF(A2>MAX(A$1:A1),ROW()-1,IFERROR(B1+1,1)),1) does work for the original test data, it doesn't work for a more complex data set, see the second screen shot below:
Original question:
I have a need to process a column (A in the example) of numbers that represents a value changing over time, and establish for how many rows the present row's number has been the largest number, and report that as illustrated in Column B.
What I can't figure out is whether there is a way of producing column B using spreadsheet functions or if I need to write some apps script to do the calculations. I've looked at the usual suspects like MAX() and LARGE() but they don't quite do what I want.
What I want is something like MAXSINCE(A99, A:A98) but that doesn't exist.
Updated data set which still doesn't have an answer for the question: for how many rows has this row had the largest value?
Logic Flow:
Check if current value A2 is greater than previous value A1; If not, return 1
If the above is true, Check whether current value is greater than the present MAX. If so, return current ROW's number - starting offset 1 else add 1 to previous value B1
Code Sample:
B2:
=IF(A2>A1,IF(A2>MAX(A$1:A1),ROW()-1,IFERROR(B1+1,1)),1)
Drag fill down

Move data to bottom of sheet

I've got a list of dates, clients, and shift data in a spreadsheet (rows A5:D34). I want to write this data to the last row of the sheet. Unfortunately, the number of rows is variable. On one week, the data may be 17 rows; later, it may be 23 rows.
I want to "archive" the data by moving the used rows to the bottom of the sheet.
I'm looking for a code (google script) solution that can work with the fact that the range to be copied is always 4 columns wide, but a variable number of rows.
Thanks for all your help!
This is a quite common problem where we might not know or have to manually include the total number of rows in the sheet. We can use, getRange() with last row values or getDataRange() to extract the range.
getRange(start_row,start_column,number_of_rows,number_of_columns);
to use the last row in the above syntax starting from A1, simply change the parameters as below.
var range = getRange(1,1,sheet.getLastRow(),sheet.getLastColumn());
The second option is to use getDataRange() which is
var range = sheet.getDataRange();
PS : Mind that range is a 2D array.
Hope this helps :)
I would suggest using sheet.getDataRange() to know how many rows and columns contain data. Once you know this you can derive the bottom row.
To quickly go through the returned values, I would suggest using sheet.getDataRange().getValues() which will return a 2 dimensional array with all the values stored in your sheet.
To know the last row containing data you can then easily do the following:
var lastRow = sheet.getDataRange.getValues().length;
Note that since the length of an array starts counting at 0 for the first row whereas when you want to set values back to your sheet your row count will start at 1. This means you need to add 1 to the lastRow count.
Now that you know the last row you can do some cleanup first to remove a previous bottom row with sheet.deleteRow(lastRow+1);
To then add a new bottom row you can simply use the append function where you pass an array with all the values for all cells of the row like this:
sheet.appendRow(["cellInColumnA";"cellInColumnB","cellInColumnC"]);

Finding the maximum value between certain row and columns in pandas df

Suppose, I have the dataframe below:
df = pd.DataFrame({'group1': ['x','xincr','xmin','xzero','yzero','ymin','s','0','1','2','3','4','5'],
'value1': [1.1,2,3,4,5,6,7,8,9,1,2,3,4]})
I want to find the maximum value in column 'value1' starting in row 7-12. Is there a way to make that specification?
Furthermore, can the output just be the value (i.e. 9).
Thank you.
This is an example of mixed indexing. Meaning you want to use labels for the columns and positions for the rows. There are a few ways to do this.
Option 1
Use .value1 to specify the columns then iloc to specify the rows 7 through 12 using 6:12.
df.value1.iloc[6:12].max()
9.0
Option 2
df.iloc[6:12, df.columns.get_loc('value1')].max()
Option 3
df.value1.values[6:12].max()
Any more options and I'll feel silly. This should do.

How do I retrieve only the top x rows from a flatfile in SSIS

I have a flatfile connection and I'm only interested in the first 10 rows of data. How can I just import the first 10 rows?
Row sampling is random so I can't use that. Is there some way I can have some sort of derived column which is an automatic row number or something and then data-split to only keep rows with that id <= 10?
Any help much appreciated!
I've used this component --> http://www.sqlis.com/post/Row-Number-Transformation.aspx
The component creates a new variable with a row number. You can use a conditional split to take the first 10 records based on the variable the component creates.
One catch is that you will need to read in the entire file. Depending on your file size you may want to seek another solution.
There isn't a direct way of doing that. You can try a work around method by using the "Data rows to skip" property:
You can "invert" your file and skip all first rows -10
Just use a lineCount component with a user variable and a conditional Split based on the value of that variable/