find and reshape function ion matlab

3 次查看(过去 30 天)
Rica
Rica 2013-1-29
Hi together!
i used this functions to find the index of some element und reshape it in a special manner.
% ind= [find(fr==8.1); find(fr==8.2); find(fr==8.3); find(fr==8.4);...... ; find(fr==10)];
id=reshape(ind,length(index)/20,[]);20:is the number of fr to be found.
%fr is a big matrix.
could someone help to write this in compact way?
thank you
  1 个评论
Jan
Jan 2013-1-29
Does the order of elements in index matter, or would ismember() do the identification sufficiently already? Are you sure, that length(index) is a multiple of 20 in every case?

请先登录,再进行评论。

回答(2 个)

Walter Roberson
Walter Roberson 2013-1-29
Your find() are mostly going to return no results.
Is there a connection between "ind" and "index" ?
Is there reason to expect that there will be no duplicate values?
Would histc() be suitable? You can get the indices of the elements from the second output of histc()

Rica
Rica 2013-1-29
Hi i forgot something: index=ind
% ind= [find(fr==8.1); find(fr==8.2); find(fr==8.3); find(fr==8.4);...... ; find(fr==10)];
id=reshape(ind,length(ind)/20,[]);20:is the number of fr to be found.
%fr is a big matrix.
what do you mean with duplicate value?
i try to find something like : ind=find[(fr==a)] whre a=8.1:step:10.
thank you!
  1 个评论
Walter Roberson
Walter Roberson 2013-1-29
Could there be more than one entry with value 8.1 ? Is it certain that the number of matches for any given "a" value will be the same?
The reshape can be simpified to
id = reshape(ind, [], 20);
You need to solve the problem that in your search range, only 8.5 and 9.0 and 9.5 and 10 are exactly representable in binary, and 8.1, 8.2, 8.3 and so on are not exactly representable. If the 8.1 value (for example) had been calculated even just slightly different then it would not match the 8.1 value that you search for. Please read http://matlab.wikia.com/wiki/FAQ#Why_is_0.3_-_0.2_-_0.1_.28or_similar.29_not_equal_to_zero.3F

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Matrix Indexing 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by