I have a data array with numbers and NaN elements. I would like to get 3 vectors with indices and corresponding values of elements other than NaN of this array.
Here is how I do it:
[x,y]=find(~isnan(A)); [~,~,z]=find(A(~isnan(A)));
Now this is not optimal. At first, the size zis different from the size xand y(this is one element shorter, and I do not know which one was omitted). Secondly, I am sure that this can be done on one line.
z
x
y
find , , :
find
% Example data A = rand(5); A(A>0.5) = NaN; iA = ~isnan(A); [x,y] = find(iA); z = A(iA(:));
find isnan , . , A:
isnan
A
[ii,jj] = find(~isnan(A)); z = A(sub2ind(size(A),ii,jj))
sub2ind, ii+(jj-1)*size(A,1).
sub2ind
ii+(jj-1)*size(A,1)
ii jj , A(~isnan(A)), z ( find).
ii
jj
A(~isnan(A))
Source: https://habr.com/ru/post/1524138/More articles:Using COPY in pqxx - c ++Java Invalid bean definition with the name 'dataSource' defined in the ServletContext resource [/WEB-INF/spring-servlet.xml]: - javaHow to check if Apache caching works? - cachingКак я могу получить все выбранные объекты флажков в AngularJS? - angularjsHow to run csh script from sh script - linuxanyway, can this LINQ end up doing too much work? - c #login to site using python and open browser login site - pythonImage of "Zoom In / Out" on a Click button in Android? - javaHaskell dynamic binding - haskellJQuery plugins native manifest file / npm - jqueryAll Articles