On Sep 23, 5:27 pm, Ruwan B. [email protected] wrote:
any help?
–
Posted viahttp://www.ruby-forum.com/.
#!/usr/bin/ruby
time1 = [ 1, 1.25, 3, 5]
y1 = [2.7, 3, 5, 10]
hy1 = Hash.new
0.upto(time1.size-1) {|i| hy1[time1[i]] = y1[i] }
time2 = [ 0, 2, 5, 6, 7, 8, 9]
y2 = [10, 1, 3, 5, 6, 7, 12]
hy2 = Hash.new
0.upto(time2.size-1) {|i| hy2[time2[i]] = y2[i] }
time_all = [time1, time2].flatten.sort
0.upto(time_all.size-1).each do |i|
puts “plotting y1 => (#{time_all[i]}, #{hy1[time_all[i]]})” if
hy1.has_key?(time_all[i])
puts “plotting y2 => (#{time_all[i]}, #{hy2[time_all[i]]})” if
hy2.has_key?(time_all[i])
end
$./h2.rb
plotting y2 => (0, 10)
plotting y1 => (1, 2.7)
plotting y1 => (1.25, 3)
plotting y2 => (2, 1)
plotting y1 => (3, 5)
plotting y1 => (5, 10)
plotting y2 => (5, 3)
plotting y1 => (5, 10)
plotting y2 => (5, 3)
plotting y2 => (6, 5)
plotting y2 => (7, 6)
plotting y2 => (8, 7)
plotting y2 => (9, 12)