Iterate over columns with a fixed row - libreoffice

is it possible to iterate over columns with a fixed row/cell and to create a new column with the values. For example I want to create a column like that:
F1=A1
F2=B1
F3=C1
F4=D1
and so on

Write the formula
=MAX(OFFSET($A$1:$A$10000;0;ROW()-1))
in cell F1 and stretch it down.
The expression ROW()-1 will take the value 0 for F1, 1 for F2, 2 for F3, and so on, and the OFFSET() function uses these values ​​to move from the range A1:A10000 to 0, 1, 2, and so on columns.

Related

OpenRefine: How can I offset values? (preceding row to the following row)

Let's suppose I have this list in OpenRefine:
A
B
C
Is there a way to move (offset values) B to A like the following?
A B
B C
With the cross() function, and v3.5 of OpenRefine (currently in beta) you can access previous or following rows by not supplying the field name. You can achieve the same by creating an index column in v3.4.
So, you can do cells.ColumnName.value +" "+ cross(row.index + 1, "", "")[0].cells.ColumnName.value to get the value of the next row appending the value of that cell in the current row, with a space.
Note that this will take the value of the row with an index higher, not necessally the row following in the display, if you use sorting.
Regards, Antoine

How to insert a structure within a structure

I have a 1x1 structure called imu_data.txyzrxyz1. It has one field called txyzrxyz1 and the value is 4877x7 double. I just want to "copy and paste" row 62 into row 63 (double up that row) so that the structure now becomes a 4878x7 structure. I've tried the following, with other versions without success:
extra_63 = imu_data.txyzrxyz1(63,:);
imu_data2.txyzrxyz1 = [{imu_data.txyzrxyz1(1:62,:) extra_63 imu_data.txyzrxyz1(63:end,:)}]
Thanks
You can index the row to duplicate twice while matrix indexing:
row_to_duplicate = 63;
yourdata = rand(100,10);
yourstruct.data = yourdata;
yourstruct.data = yourstruct.data([1:row_to_duplicate, row_to_duplicate:end],:)
So in case of 63, 1:row_to_duplicate will create a column vector from 1:63, and row_to_duplicate:end will create a column vector from 63:100 in this example. When combining these, 63 will occur twice, hence that row is duplicated.
You were almost there, you only had to get rid of the {}'s and put the data in the right orientation by using ; instead of a space between matrix entries to vertically concatenate instead of horizontally:
extra_63 = imu_data.txyzrxyz1(63,:);
imu_data2.txyzrxyz1 = [imu_data.txyzrxyz1(1:62,:); extra_63; imu_data.txyzrxyz1(63:end,:)]

How to add values to last column of a table based on certain conditions in MATLAB?

I have a 29736 x 6 table, which is referred to as table_fault_test_data. It has 6 columns, with names wind_direction, wind_speed, air_temperature, air_pressure, density_hubheight and Fault_Condition respectively. What I want to do is to label the data in the Fault_Condition (last table column with either a 1 or a 0 value, depending on the values in the other columns.
I would like to do the following checks (For eg.)
If wind_direction value(column_1) is below 0.0040 and above 359.9940, label 6 th column entry corresponding to the respective row of the table as a 1, else label as 0.
Do this for the entire table. Similarly, do this check for others
like air_temperature, air_pressure and so on. I know that if-else
will be used for these checks. But, I am really confused as to how I
can do this for the whole table and add the corresponding value to
the 6 th column (Maybe using a loop or something).
Any help in this
regard would be highly appreciated. Many Thanks!
EDIT:
Further clarification: I have a 29736 x 6 table named table_fault_test_data . I want to add values to the 6 th column of table based on conditions as below:-
for i = 1:29736 % Iterating over the whole table row by row
if(1st column value <x | 1st column value > y)
% Add 0 to the Corresponding element of 6 th column i.e. table_fault_test_data(i,6)
elseif (2nd column value <x | 2nd column value > y)
% Add 0 to the Corresponding element of 6 th column i.e. table_fault_test_data(i,6)
elseif ... do this for other cases as well
else
% Add 1 to the Corresponding element of 6 th column i.e. table_fault_test_data(i,6)
This is the essence of my requirements. I hope this helps in understanding the question better.
You can use logical indexing, which is supported also for tables (for loops should be avoided, if possible). For example, suppose you want to implement the first condition, and also suppose your x and y are known; also, let us assume your table is called t
logicalIndecesFirstCondition = t{:,1} < x | t{:,2} >y
and then you could refer to the rows which verify this condition using logical indexing (please refer to logical indexing
E.g.:
t{logicalIndecesFirstCondition , 6} = t{logicalIndecesFirstCondition , 6} + 1.0;
This would add 1.0 to the 6th column, for the rows for which the logical condition is true

Removing rows from all columns based on values of one column

i have a data of 732x26 and one of the column contains unwanted values, i used
logicalIndex = FOMassFlow > MeanFOMassFlow;
FOMassFlow = FOMassFlow(FOMassFlow ~= 0)
to remove the unwanted values of the particular column. How can i remove the rows of the unwanted values in the data of 732x26 ? (example, unwanted values found in column 5 row 6, i would like to remove the entire row 6 in the data of 732 rows by 26 columns)
To remove an entire row from a matrix, so in your case it's row 6, simply do:
FOMassFlow(6,:) = [];
This will mutate FOMassFlow so that you have 731 rows with row 6 removed.

Extracting rows from .mat table using for loop in MATLAB

What I have is a variable X which has values assigned to it in the form of a table of 9 columns and around 100 rows. Here is an example:
X =
Columns 1 through 7
-2.2869 -1.1168 0.1430 -4.0753 1.7620 -6.3229 -3.1997
-2.2504 -1.1022 0.2046 -3.9865 1.7423 -6.2172 -3.1231
-2.2138 -1.0876 0.2663 -3.8977 1.7226 -6.1115 -3.0465
-2.1772 -1.0730 0.3279 -3.8089 1.7029 -6.0058 -2.9700
I need to create a for loop that extracts the first r rows of the first 'p' colmuns. For example r=3 and p=4.
Any idea on how I can do that?
I suggest you don't use a for-loop, but rather index directly into the matrix:
out = X(1:r,1:p)
returns the first r rows and p columns of X.