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

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.

Related

How to assign the column number to a parameter

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.

Average of the values for duplicate keys in a cell array of (key,value) in matlab

I have 2 columns in a cell array as key and value
I want a single value corresponding to every key so I removed the duplicate value as: wd=finalAlp93val;
[~,idx]=unique(strcat(wd(:,1),wd(:,2)) , 'rows')
finalAlp93val = wd(idx,:)
But it resulted in higher variation in result. How can I average all the values with the same key in matlab. The number of rows for each key is variable here. (Here key is the first column and value is the second column and I want to achieve the avg of values for each key.)
here's how using a minimal example:
key=wd(:,1);
val=wd(:,2);
ukey=unique(key);
for n=1:numel(ukey)
mean_value(n)=mean(val(key==ukey(n)));
end
so you can present them together as follows:
[ukey(:) mean_value(:)]

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)

Selecting cells in a table using for-loop

I need to obtain individual values from cells incrementally.
For example in a table called "T":
Can Matlab create a loop to yield the following?:
T(1,1)
T(1,2)
T(1,3)
T(1,4)
and so forth.
First of all the first parameter in MATLAB equals the row, the second the column. So following your picture you would want to extract a complete column. Then you have to loop over your first parameter and keep the 2nd constant.
So not sure if this is really what you want but:
for k = 1:size(T,1)
T(k,1)
end
would write all elements in column 1 row after row. This is because size(T,1) returns the No. of rows in your Table. So by looping over all rows you return one column. Easier with the same result would be:
T(:,1)
which would return the whole first column.
If you don't want them to be displayed but to use them as entries for another variable use:
new_T = T(:,1);
The ; makes sure that the command isn't displayed on the console. And the new_T would have all entries from column 1.
Another example:
new_T2 = T(1:500, 4);
This would result in the first 500 elements from column 4.
Hopefully this solves your question, if not please explain your question more detailed.

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))