To resolve issues starting MATLAB on Mac OS X 10.10 (Yosemite) visit: http://www.mathworks.com/matlabcentral/answers/159016
Hi I have a matrix that is called file1=[1109x1] and another matrix that is caled rxn=[1170x7] i need to know if the contents of the 'file1' exist in column#5 of the rxn and if the answer is yes, the whole content of the related row in 'rxn' would be copied to a new matrix, what should i do? Please help me on this issue Thank you alot!
[EDITED, Jan, moved from comment sections]
Here is what my data exactly is: File1 contains 1column x 1109rows and each cell contains numbers like this: 22.214.171.124
Rxn contains 7column x 1170rows. In every cells of column#5 exists numbers like what it was in file1 (126.96.36.199) I am going to compars every cells of file1 with cells of rxn column#5 and if the numbers were exactly the same, the whole content of the related row in rxn would be copied to a new matrix Please note that i need the exact properties of each cell
No products are associated with this question.
You could use ismember and indexing values to determine which rxn columns have corresponding values within file1 but this can also be solved using a set of loops as shown:
count= 0; for i = 1 : length(file1) for j = 1 : length(rxn) if file1(i) == rxn(j,5) count = count + 1; finalMatrix(count,:) = rxn(j,:); end end end
The finalMatrix will be a matrix containing all of the rows of rxn that have their column 5 values identified within file1
file1 = randi(1000, 1, 1109); % Test data rxn = randi(1000, 1170, 7);
match = ismember(rxn(:, 5), file1); result = rxn(match, :);
If I understand your intent correctly, you want every row of rxn for which the value in the 5th column is one of values in the vector file1. If so:
result = rxn(ismember(rxn(:,5),file1),:);
Ok big issue here but not impossible. The following procedure works in Matlab R2012a.
Import 3 files: One will be Rxn (7 columns), File1 and other called "Var1" will be column 5 of Rxn. When you import this to Matlab you will have string information not data. Because the information is in Excel (for example) use the function num2str in the import process.
Now, for each string in File1, we begging the search in Var1. This will work for the search of the first string in File1.
How R works. For 188.8.131.52 we have 8 characters. Then, if R= 36 all the string match and we find what we are looking for. If you remove the sum, an error will appear. At the end I provide a code that you can check. If the number of characters change, establish a condition in Step 3 according to string data search.
R is column vector. Find in R the value 36. Remember, 184.108.40.206 we have 8 characters, and the sum of 1 to 8 is 36.
RR=find(R==36) %Now you have the rows
New matrix and copy process
%Step 1 Search a value (A(1,:)). This is the first value in A. It could be the first element of File1
%My Rxn matrix (2 columns A,B)
Var1=A; %search in this column
File1=A(1,:) %search this data
RR=find(R==21) %Data are like 1.11.1, 6 characters and sum(1 to 6)=21
Feel free to make a comment and verify that the code supplied works before comment.