English 中文(简体)
如何安排病媒部分?
原标题:How to arrange elements of vector in Fortran?

我有两个阵列,即: y 含有实际数字,NAs. ymiss 含有1 s和0 s,这样,如果 y(i,j)=NA, ymiss (i,j)=0, 否则1。 我也拥有1英寸,显示在 y(1:p,n)的实际数字有多少,因此,古丁的数值为0到p。

在区域方案拟订语言中,我可以做到如下:

if(ydim!=p && ydim!=0)  
  y(1:ydim(t), t) = y(ymiss(,t), t)

这部法律像此法一样,安排了所有实际数量和数量。

first there s for example y(,t) = (3,1,NA,6,2,NA) after the code it s y(,t) = (3,1,6,2,2,NA)

现在,我只需要第一批1:ydim(t),这样,就没有问题。

问题是,我如何能够像在安定中那样做?

感谢

Jouni

问题回答

“声明”和“合并”的内在功能是强大的,在阵列的某些位置上运作,但它们没有将物品移到阵列的前线。 具有明确的索引的旧编码(可并入功能)例如:

k=1
do i=1, n
   if (ymiss (i) == 1) then
      y(k) = y(i)
      k = k + 1
   end if
end do

你们想要做的是使用“包装”内在的阵容。 1. 变形成一个逻辑阵列: 页: 1 然后使用诸如(没有第二指数测试):

iii)


添加实例代码,显示“在什么地方”、“在什么地方”和“包装”等固有术语的使用。 “只有”才能解决问题,但“包装”可以解决。 举例来说,我使用了“设计”;-90”作为NaN。 “y (ydim+1:LEN) =-99.0”是禁止化学武器组织要求的吨数,他不需要使用这些元素。

program test1

integer, parameter :: LEN = 6
real, dimension (1:LEN) :: y = [3.0, 1.0, -99.0, 6.0, 2.0, -99.0 ]
real, dimension (1:LEN) :: y2
logical, dimension (1:LEN) :: ymiss
integer :: ydim

y2 = y
write (*,  (/ "The input array:" / 6(F6.1) )  )  y

where (y < -90.0)
   ymiss = .false.
elsewhere
   ymiss = .true.
end where

ydim = count (ymiss)

where (ymiss) y2 = y
write (*,  (/ "Masking with where does not rearrange:" / 6(F6.1) )  )  y2

y (1:ydim) = pack (y, ymiss)
y (ydim+1:LEN) = -99.0
write (*,  (/ "After using pack, and ""erasing"" the end:" / 6(F6.1) )  )  y


stop

end program test1

产出是:

The input array: 3.0 1.0 -99.0 6.0 2.0 -99.0

Masking with where does not rearrange: 3.0 1.0 -99.0 6.0 2.0 -99.0

After using pack, and "erasing" the end: 3.0 1.0 6.0 2.0 -99.0 -99.0

简言之,你可以把纳储存在一系列实际数字中,你只能储存真实数字。 因此,你很可能想用你的数据中可能不具备的一些价值来取代那天:大()可能是合适的。 2D阵列对于Fortan来说根本不存在问题。 您不妨利用2D系列的逻辑来取代古兰经,而不是2D系列的1和0。

实现你所希望的,没有简单、内在的,你需要写一份职务。 然而,做事的更部分方式是将各种逻辑作为mask用于你想要开展的行动。

因此,这里有一些零碎的换代法没有测试:

! Declarations
real(8), dimension(m,n) :: y, ynew
logical, dimension(m,n) :: ymiss

! Executable
where (ymiss) ynew = func(y)  ! here func() is whatever your function is




相关问题
jQuery: hidden elements - general question

when elements are hidden, you can t read eg. their dimensions, is this a general javascript problem or is there maybe a workaround in jQuery? i m having eg. some tabs which contain widgets, ...

Button Element with Type Submit & PHP Challenges

Recently I change from <input type="button"> to <button> in my forms however the form being processed by PHP wouldn t then submit to the database. Am I missing something in my code? ...

Javascript Checking array for presence of a specific number

I have search through quite a lot of questions here, but havent found one that i think fits my bill, so if you know of one please link to it. I have an array that i want to search through for a ...

IE6 floated element wrapping problеm

I am trying to get tags to wrap to the next line by left floating them. In firefox the text will wrap onto the start of the next line, however IE6 will wrap the text onto the line directly under the ...

热门标签