example
My text file is like
string 1 12 13 14 16 11 41 25 26 32 25 26 27
string 2 23 15 26 28 12 15 19 17 35 65 84 12
string 3 and so on...
I want that if I ask for string 1 , it will give me the corresponging matrix under string 1 and the size of the matrix is also not known i.e. 12 13 14 16 11 41 25 26 32 25 26 27
will anyone tell me how to do this?
thanks
答案 0 :(得分:0)
您应该执行以下操作:
1 - 将字符串转换为整数/矩阵
M1 = str2num(string1) - http://www.mathworks.com/help/matlab/ref/str2num.html
M2 = str2num(string2)
2 - 如果要查找相应的值,只需比较:
for i=1:length(M1)
[~,M3(i)]=ismember(M1(i),M2)
end
M3
会为您提供M2
中匹配的索引。