How to assign the column number to a parameter - anylogic

enter image description here
In the screenshot, you can see a datatable. My problem is to assign the column number with sum zero to a parameter. I can add individual column
selectFirstValue("SELECT SUM(c1) FROM precedence;");
with this code and find out its sum.
Here is my datatable name is "precedence".
Now is it possible to do this column sum in a loops are any other way where it makes the sum of each column and assign the column number to a parameter when its sum is zero. In my case I will only have one column with sum zero.

Related

MATLAB matrix operation

I am having matrix with approx 3000 rows(changing) and 3 columns.
I have count of both rows and columns.
I am trying to plot the graph:
x=1:3000;
plot(matrix(x,1))
is there any way that I can include all rows in the plot instruction itself so that I can remove 'x=1:3000' ?
Also, I want to divide, 1st column of matrix which have 3000 rows into another matrix of 3 columns each with 1000 rows. Any specific instruction for this ?
I have made for loop for this and then i am placing individually the elements in the new array. But its taking long time.
As to the plotting issue, using the colon operator will plot all rows for your desired column:
plot(matrix(:,1));
EDIT: You mentioned you were a beginner. In case you haven't seen the colon operator used like this before, a colon operator all by itself when indexing into a matrix essentially means "all __", either "all rows" if in the first position or "all columns" if in the second position.
As for the second question, of splitting one column into a new matrix with multiple columns, you can use the reshape() function, which takes the input matrix to be reshaped and a number of output rows and columns. For example, to split the first column of matrix into 3 columns and put them into newMatrix, use the following:
newMatrix = reshape(matrix(:,1),[],3);
Note that the above code uses [] in the second argument (the number of rows argument) to mean "automatically determine number of rows".This is automatically determined based on the number of columns, which is defined in the third argument here as 3. The reshape function requires that the number of output rows * output columns be equal to input rows * input columns. So in the above case this will only work if the starting matrix has a number of rows which is divisible by 3.

Select column from matrix where some other column satisfies given condition

My matrix has 10 columns. I want to select all rows where the first column is less than 4. If I use
data(data(:,1)<4)
Only the first column is selected.
How do I display all corresponding column values?
How do I select a single corresponding column, e.g., select column 2 where value of column1<4?
How about
data( data(:,1) < 4, : )
data(data(:,1)<4,:)
: indicates all columns. Since data is 2-d matrix, you need to input two parameters, one for row and one for column.
If you need specific columns like column 2
data(data(:,1)<4,2)

Taking average of one column with w.r.to other column

I have two columns in .std file. I want average of the second column values corresponding to all values ranging from some value (eg. 1.0- 1.9) in first column how can I program in Matlab?
Say, a is the name of your two column matrix. If you want to find all of the values in the first column in the range of 1.0 - 1.9 and then use those entries to find the mean in the second column you can do this:
f = find(a(:,1)>=1 & a(:,1)<=1.9)
m = mean(a(f,2))
find will find the values that lie within this range and return the index, and a(f,2) accesses those indices in the in the second column and takes the mean. You can also do it with one line like so:
m = mean(a((a(:,1)>=1 & a(:,1)<=1.9),2))

Excel: Check if Cell value exists in Column, and return a value in the same row but different column

After checking if a value exists in a column, I want to return the value of the cell in the same row to a different column.
Specifically, I am checking to see if any values in column O match with values from column A. If they do I want to take the corresponding value from cells in the same row as the matched items in column A, but these values are in column f. I then want to take those values from column f and put them in the same rows as the values from column O.
This is the formula I've tried:
=IF(ISNA(MATCH(O2,$A$2:$A$1589,0)),"no match", VLOOKUP(O2,$A$1:$z$14000,16,FALSE))
This returns a "no match" for all the cells in the column P. I tried messing around with the col_index_num in the VLOOKUP function, but the best I can do is get it to return zeros, which aren't the right values anyway.
I think the following formula should give you what you are trying to get. If I understand your question correctly, you want to return the value in column F that is in the same row as the match: hence, the range I use for column F is the same length as the range for column A.
=IFERROR(INDEX($F$2:$F$1589,MATCH(O2,$A$2:$A$1589,0),1),"no match")
Working outward, here is what is going on.
The match function is looking in column A for an exact match of the value in O2.
If it finds a match, it returns the relative position of the matching value in the column A lookup range.
If it finds no match, it returns an error value.
The index function returns the value in the i th row and j th column of the index range, in this case the row that was found in the match, and the first (and only) column in the index range, column F.
Finally, those two functions are wrapped in an IFERROR function, to catch the error value that will be generated if there is no match, and return instead the string "no match".
This formula would be entered in cell P2 and copied down through the last row of data in column O.

Getting the Sum of the Contents of Rows

I have a column with dollar amounts, such as:
$1.00
$4.00
$100.00
and so on. These values are put into the column by calculating the % of another column. I want to get the sum of all the dollar amounts of that column. I cant use Sum(data) because its static data in the column. Is there a way to get the sum easily?
Thanks!
There are a couple of different ways to deal with this:
If it's the same percentage being applied to each row, sum the original column and apply the same percentage to that sum.
If the original source of the data is from a database, do the percent calculation in your Dataset's SQL query, then use the Sum function in your Tablix as usual.
If these don't apply, you'll need to give more detailed information about your problem.