I had a Quickbird image and after running the FLAASH, I would like to normalize the image as following: if the pixel>0 or =10000, multiply it by 1; if pixel < or = 0 multiple it by 0; if pixel >0 and <10000 multiple it by its float value and devide the result by 10 000.
I wrote the IDL code as following, but my conditional statement is error. Could you please help me to fix the conditional statement.
Thanks so much for your help.
Lien
My IDL code:
pro correct_reflec
fname='D:\Quick\BA.dat'
envi_open_file, fname, r_fid=fid,NO_REALIZE=1
ENVI_FILE_QUERY,fid,DIMS=dims,NS=ns,NL=nl,NB=nb, pos=pos
map_info=envi_get_map_info(fid=fid)
b1 = ENVI_GET_DATA(FID=fid, dims=dims, pos=1)
ns=n_elements(b1[*,0])
nl=n_elements(b1[0,*])
br=fltarr(ns,3,nl)
CASE 1 of
b1 le 0: br(*,0,*) = (b1)*0
b1 ge 10000: br(*,0,*)= (b1)* 1
else: br(*,0,*)= b1*foat(b1)/(10000)
ENDCASE
b2 = ENVI_GET_DATA(FID=fid, dims=dims, pos=1)
CASE 1 of
b2 le 0: br(*,1,*) = b2*0
b2 ge 10000:br(*,1,*)=b2*1
else: br(*,1,*)=b2*foat(b2)/10000
ENDCASE
b3 = ENVI_GET_DATA(FID=fid, dims=dims, pos=2)
CASE 1 of
b3 le 0:br(*,2,*) = b3*0
b3 ge 10000: br(*,2,*)=b3*1
else br(*,2,*)=b3*foat(b3)/10000
ENDCASE
envi_write_envi_file, br, map_info=map_info, out_name='D:\Quick\test', r_fid=fid
END
You are missing a ":" in the ELSE clause of the third CASE statement. Is that where the syntax error is showing?
Related
I am using rbx.lua. Everything works except for the color changing at the bottom.
Please note that the script is not finished, I just stopped at p1.
--Variables--
local r1 = math.random(100)
local r2 = math.random(100)
local r3 = math.random(100)
local p1 = workspace.Part1
local p2 = workspace.Part2
local p3 = workspace.Part3
local c1 = game.ServerStorage.green
local c2 = game.ServerStorage.yellow
local c3 = game.ServerStorage.red
local grn = NumberRange.new(0, 45)
local ylw = NumberRange.new(46, 75)
local red = NumberRange.new(76, 100)
--Randomizing Y Vector Between 0 and 100--
p1.Size = Vector3.new(4, r1, 4)
p2.Size = Vector3.new(4, r2, 4)
p3.Size = Vector3.new(4, r3, 4)
--Setting up colors--
if p1.Size.Y == grn then
p1.BrickColor = c1
end
if p1.Size.Y == ylw then
p1.BrickColor = c2
end
if p1.Size.Y == red then
p1.BrickColor = c3
end
Try this instead:
Remove the NumberRange variables, and replace the if blocks with this:
if p1.Size.Y <= 45 then
p1.BrickColor = c1
elseif p1.Size.Y <=75 then
p1.BrickColor = c2
else
p1.BrickColor = c3
end
The elseif block won’t be checked unless the p1.Size.Y value is above 45. Same for the else block: it won’t be entered unless the value is above 75.
Hope that helps! You were checking to see if a specific value was equal to (==) a range...not if the value was in the range.
I have a Julia data frame where one column is called 'close' and I want to add another column to the data frame called 'sma' which is a simple moving average of 'close'. Thanks to anyone who can help!
I noticed a problem in the code amrod. It doesn't account for the first length of SMA that doesn't have enough previous data points for a good SMA and also gives double the SMA that is asked for. I changed it to input zeros up to that point, I also changed the variable names when I was figuring out how it works.
function makeSMA(data, SMA)
len = length(data)
y = Vector{Float64}(len)
for i in 1:SMA-1
y[i] = NaN
end
for i in SMA:len
y[i] = mean(data[i-(SMA-1):i])
end
return y
end
check this:
function ma{T <: Real}(x::Vector{T}, wind::Int)
len = length(x)
y = Vector{Float64}(len)
for i in 1:len
lo = max(1, i - wind)
hi = min(len, i + wind)
y[i] = mean(x[lo:hi])
end
return y
end
x = collect(1:100)
y = ma(x, 4)
then you can hcat(x, y).
EDIT:
If you want a backwards-looking MA you can use something like
function ma{T <: Real}(x::Vector{T}, wind::Int)
len = length(x)
y = Vector{Float64}(len)
for i in 1:len
if i < wind
y[i] = NaN
else
y[i] = mean(x[i - wind + 1:i])
end
end
return y
end
Need help with writing this Excel function into a Macro, please help
A1=7 B1=1 C1=4
A2=8 B2=2 C2=5
A3=9 B3=3 C3=6
if A1 = A1(7), answers will equal to B1 * C1 = 1*4 = 4
if A1 = A2(8), answers will equal to B2 * C2 = 2*5 = 10
the function works perfectly in the excel cell,
SUMPRODUCT((A1:A3=A1)+0,B1:B3,C1:C3)
however, the vba doesn't not work.
With Worksheets("Sumproduct")
.Range("D1").Value = Application.WorksheetFunction.SumProduct((.Range("A1:A3" = A1)+ 0 , .Range("B1:B3"), .Range("C1:C3"))`
I have an assignment in which I need to swap two integers without using third variable.
I'm not sure how to do this. How would I code this?
Yes, it's possible:
Dim var1 = 1
Dim var2 = 2
var1 = var1 + var2
var2 = var1 - var2
var1 = var1 - var2
But why do you need it? The code becomes abstruse.
Lets assume
a = 10;
b = 20;
a = a + b; // a = 30
b = a - b; // b = 10
a = a - b; // a = 20
Values swapped.
Read up on the "xor swap algorithm."
You can find an answer here:
http://www.java2s.com/Tutorial/VB/0040__Data-Type/Swaptwointegerswithoutusingathird.htm
firstValue = firstValue Xor secondValue
secondValue = firstValue Xor secondValue
firstValue = firstValue Xor secondValue
Dim a As Integer
Dim b As Integer
a= 1
b= 2
a = a Xor b
b = a Xor b
a = a Xor b
To swap two numeric variables do like this
a = a + b;
b = a - b;
a = a - b;
OR
a = a xor b;
b = a xor b;
a = a xor b;
where a and b are variables to be swapped
theoretically 3 ways
a = 4 , b = 5
1. Using XOR
a = a XOR b = 4 XOR 5 = 9
b = a XOR b = 9 XOR 5 = 4
a = a XOR b = 9 XOR 4 = 5
2. Using +,-
a = a+b = 4+5 = 9 // should not overflow
b = a-b = 9-5 = 4
a = a-b = 9-4 = 5
3. Using *,/
a = a*b = 4*5 = 20 // should not overflow
b = a/b = 20/5 = 4 // should not overflow and should not be irrational number
a = a/b = 20/4 = 5 // should not overflow and should not be irrational number
The Xor or a+b algorithms above work and are the best way to do this, but just an example of a weird way to do it. Still not sure why you would want to do this. Just build a function that you supply two values ByRef and have it do the standard swap method.
Dim newList as New List(Of Integer)
newList.Add firstvalue
newList.Add secondValue
newList.Reverse
secondValue = newList.Item(0)
firstValue = newList.Item(1)
Take two text boxes and a command box.In command box type this code.
text1.text=val(text1.text) + val(text2.text)
text2.text=val(text1.text) - val(text2.text)
text1.text=val(text1.text) - val(text2.text)
Check link written for you
Approach#1.
Addition and Subtraction Method
Integer a, b
read a and b
a= a+b;
b=a-b;
a=a-b;
Problem:
Incorrect result when sum of numbers will exceed the Integer range.
Approach#2.
Multiplication and Division Method
Integer a, b
read a and b
a=a*b;
b=a/b;
a=a/b;
Problems:
If the value of a*b exceeds the range of integer.
If the value of a or b is zero then it will give wrong results.
Approach#3.
XOR Method
Integer a , b
read a and b
a=a^b;
b=a^b;
a=a^b;
Best approach to solve this problem without any pitfalls.
I've been doing past paper questions and keep coming up against these questions that deal with 3 valued logic. My notes mention it but don't give examples that relate to those asked in exams.
I understand the basis that True = 1, False = 0 & Unknown = 1/2 as well as And = Min, Or = Max and Not(x) = 1-x. However I do not know how to apply it to questions such as those below:
In SQL, discuss the possible truth values of the following expression:
R.a > R.b OR R.a <= 0 OR R.b >= 0
Justify your answer.
And:
The phone and age fields of the Owner table might have null values in
them. Considering all possible combinations, show which of the three
truth values might be returned by the expression:
phone = ’141-3304913’ OR age <50 OR age >= 50
Any help in clarifying these for me would be really appreciated :)
I will focus on the concrete example, which is more proper for clarifying things.
Put simply, your logical expression is made of a conjunction of three clauses
C1: phone = '141-3304913'
C2: age < 50
C3: age >= 50
for which tri-boolean logic states that the result is
True, if any clause is true
False, if all clauses are false
Unknown, in all the other cases
Consequently, if the value associated with True is the largest, with False is the smallest, and with Unknown is any intermediate value, then taking the MAX for a conjunction proves correct. Similarly, a disjunction works with the MIN function. Negation works as long as we interpret any value between 0 and 1 (excluded) as Unknown; clearly, if we take 1/2 then the negation function is "stable", but that does not really matter in mathematical terms.
More operatively, the clauses clearly react to the following values (instances) of your phone variable P and your age variable A:
P1 such that P1 = '141-3304913'
P2 such that P2 <> '141-3304913'
P3 such that P3 = NULL
A1 such that A1 < 50
A2 such that A2 >= 50
A3 such that A3 = NULL
In terms of satisfaction of the clauses, we have
P1 -> C1 = 1
P2 -> C1 = 0
P3 -> C1 = 1/2
A1 -> C2 = 1, C3 = 0
A2 -> C2 = 0, C3 = 1
A3 -> C2 = C3 = 1/2
In general there exist 3*3 possible combinations, since each of your two variables takes three possible values:
P1 A1: C1 = 1, C2 = 1, C3 = 0 -> MAX(1,1,0) = 1 -> true
P1 A2: C1 = 1, C2 = 0, C3 = 1 -> MAX(1,0,1) = 1 -> true
P1 A3: C1 = 1, C2 = 1/2, C3 = 1/2 -> MAX(1,1/2,1/2) = 1 -> true
P2 A1: C1 = 0, C2 = 1, C3 = 0 -> MAX(0,1,0) = 1 -> true
P2 A2: C1 = 0, C2 = 0, C3 = 1 -> MAX(0,0,1) = 1 -> true
P2 A3: C1 = 0, C2 = 1/2, C3 = 1/2 -> MAX(0,1/2,1/2) = 1/2 -> unknown
P3 A1: C1 = 1/2, C2 = 1, C3 = 0 -> MAX(1/2,1,0) = 1 -> true
P3 A2: C1 = 1/2, C2 = 0, C3 = 1 -> MAX(1/2,0,1) = 1 -> true
P3 A3: C1 = 1/2, C2 = 1/2, C3 = 1/2 -> MAX(1/2,1/2,1/2) = 1/2 -> unknown
In particular, since C2 and C3 are mutually exclusive, you never get False as a result of the conjunction.
The expression R.a > R.b OR R.a <= 0 OR R.b >= 0 instead presents these cases:
R.a <= 0, R.a > 0, R.a = unknown
R.b >= 0, R.b < 0, R.b = unknown
R.a - R.b > 0, R.a - R.b <= 0, R.a - R.b = unknown
Apparently we have three variables and 27 possible cases, but several related to R.a - R.b can be trivially ruled out.