finding conetnts of a cell in another one
정보
이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.
이전 댓글 표시
Here is what my data exactly is: File1 contains 1column x 1109rows and each cell contains numbers like this: 2.11.7.8
Rxn contains 7column x 1170rows. In every cells of column#5 exists numbers like what it was in file1 (2.11.7.8) 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
댓글 수: 6
Daniel Shub
2012년 9월 21일
Where have you gotten to so far? Can you read in File1? Have you created Rxn? How are you trying to compare the arrays? What about the edge cases (i.e., no matches or multiple matches).
Daniel Shub
2012년 9월 21일
How is this different from your other question: http://www.mathworks.com/matlabcentral/answers/48563-finding-contents-of-cell-in-another-one
babak
2012년 9월 21일
Hello Babak
Ok big issue here but not impossible. The following procedure works in Matlab R2012a. No answer space so I answer here.
Step 1
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.
Step 2
Now, for each string in File1, we begging the search in Var1. This will work for the search of the first string in File1.
for i=1:1170
R(i,1)=sum(find(A(i,:)==File1(1,:)),2);
end
How R works. For 2.11.7.8 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.
Step 3
R is column vector. Find in R the value 36. Remember, 2.11.7.8 we have 8 characters, and the sum of 1 to 8 is 36.
RR=find(R==36) %Now you have the rows
Step 4
New matrix and copy process
for i=1:size(RR,1)
Newm(i,:)=Rxn(RR(i,1),:)
end
Code
%Step 1 Search a value (A(1,:)). This is the first value in A. It could be the first element of File1
a=randn(100,4);
A=[num2str(abs(round(a(:,1)))),repmat('.11.',100,1),num2str(abs(round(a(:,2))))];
B=[num2str(abs(round(a(:,3)))),repmat('.11.',100,1),num2str(abs(round(a(:,4))))];
%My Rxn matrix (2 columns A,B)
Rxn=[A,B];
Var1=A; %search in this column
File1=A(1,:) %search this data
%Step 2
for i=1:size(Rxn,1)
R(i,1)=sum(find(Var1(i,:)==File1(1,:)),2);
end
%Step 3
RR=find(R==21) %Data are like 1.11.1, 6 characters and sum(1 to 6)=21
%Step 4
for i=1:size(RR,1)
Newm(i,:)=Rxn(RR(i,1),:)
end
Feel free to make a comment and verify that the code supplied works before comment.
Regards
Javier
babak
2012년 9월 21일
babak
2012년 9월 21일
답변 (0개)
이 질문은 마감되었습니다.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!