Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
i want to load my image call caltrain, there is 30 img.
i used code
for i = 0:30
imgINumber = i;
imgPNumber = i+2;
if imgINumber < 10
imgIFile = sprintf('C:\sequence01_caltrain_gray\caltrain/gray/%s00%d.ras',imageName, imageName, imgINumber);
elseif imgINumber < 100
imgIFile = sprintf('C:\sequence01_caltrain_gray\caltrain/gray/%s0%d.ras',imageName, imageName, imgINumber);
end
if imgPNumber < 10
imgPFile = sprintf('C:\sequence01_caltrain_gray\caltrain\gray/%s00%d.ras',imageName, imageName, imgPNumber);
elseif imgPNumber < 100
imgPFile = sprintf('C:\sequence01_caltrain_gray\caltrain\gray/%s0%d.ras',imageName, imageName, imgPNumber);
end
imgI = double(imread(imgIFile));
imgP = double(imread(imgPFile));
imgI = imgI(:,1:352);
imgP = imgP(:,1:352);
but error:
Error using ==> imread
Can't open file "C:" for reading;
you may not have read permission.
i need solution for this
thanks
Either double your backslashes or replace all the backslashes with slashes in your sprintf calls.
Related
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
Hi I want to create A YML file and load them as instance variables instead. How can I do that.
yml_File.yml File ::
default:
browserversion: 43
dev:
browser_02: iexplore
qa_01:
browser_default: chrome
qa_02:
browser_default: safari
Check the below Code::
p yml_File = YAML.load_file(File.dirname(__FILE__).gsub('/', '\\') + '\\Profiles.yml')
yml_File.each_key {|key_Value|
va = yml_File[key_Value].to_s
var_name = "##{key_Value}" # the '#' is required
self.instance_variable_set(var_name, va)
p "Name of Instance variable '#{key_Value}' is :: " + var_name.to_s + ' - And Key value is : ' + eval("##{key_Value}")
}
p #dev
p #qa_01
p #qa_02
Note - Ruby 1.9+ atleast
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 7 years ago.
Improve this question
I have quite the annoying bug right now, whenever I run this code
function player.detect()
for j = #bullet, 1, -1 do
if CheckCollision(bullet[j].x, bullet[j].y, bullet.w, bullet.h, enemy.x, enemy.y, enemy.w, enemy.h) then
table.remove(bullet, j)
end
end
end
for j = #enemy, 1, -1 do
if CheckCollision(bullet.x, bullet.y, bullet.w, bullet.h, enemy[j].x, enemy[j].y, enemy.w, enemy.h) then
table.remove(enemy, j)
end
end
end
end
It says: Error: Syntax error: player.lua:118: '' expected near 'end'
Yes, this is player.lua, and yes the code displayed is line 104-119. Thanks for reading! Anything helps!
You have too many ends!
function player.detect()
for j = #bullet, 1, -1 do
if CheckCollision(bullet[j].x, bullet[j].y, bullet.w, bullet.h, enemy.x, enemy.y, enemy.w, enemy.h) then
table.remove(bullet, j)
end
end
for j = #enemy, 1, -1 do
if CheckCollision(bullet.x, bullet.y, bullet.w, bullet.h, enemy[j].x, enemy[j].y, enemy.w, enemy.h) then
table.remove(enemy, j)
end
end
end
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
Unable to Write Inline Aggregate function in Matlab.
X1, X2 are array variables. And mb and nb are size of BUS DATA.
V is the voltage function, delta is the angle.
% objf=inline('sum(V(mb)^2+V(nb)^2-2*V(mb)*V(nb)*cos(delta(mb)-delta(nb)))','mb','nb');
% old code running
objf=inline('4*x1^2-2.1*x1^4+(x1^6)/3+x1*x2-4*x2^2+4*x2^4','x1','x2');**
*Error using inlineeval (line 15)
Error in inline expression ==> sum(V(mb).^2+V(nb).^2-2.*V(mb).*V(nb).cos(delta(mb)-delta(nb)))
Undefined function 'V' for input arguments of type 'double'.
Error in inline/subsref (line 24)
INLINE_OUT_ = inlineeval(INLINE_INPUTS_, INLINE_OBJ_.inputExpr, INLINE_OBJ_.expr);
Error in deeee (line 48)
fx=objf(x(:,1),x(:,2));
where variable aer defined as below..
busdata = bus; % ARRAY OF INPUTs
j=sqrt(-1);
P=[];Q=[];
nb=busdata(:,1);
kb=busdata(:,2);Vm=busdata(:,3);deltad=busdata(:, 4);Pd=0.8*busdata(:,5)/basemva;Qd=.8*busdata(:,6)/basemva;
Pg=busdata(:,7)/basemva;Qg=busdata(:,8)/basemva;Bsh=busdata(:,11);Qmin=busdata(:,9)/basemva;Qmax=busdata(:,10)/basemva;
G=real(Ybus);B=imag(Ybus);slb=find(kb==1);pv=find(kb==2);pq=find(kb==0);pvq=find(kb~=1);npv=length(pv);
npq=length(pq);npvq=length(pvq);nbus=max(nb);
delta(nb) = pi/180*deltad(nb);
V(nb) = Vm(nb).*(cos(delta(nb))+j*sin(delta(nb)))';
P(nb)=(Pg(nb)-Pd(nb));
flag=0;
What you're locking for is anonymous functions
objf = #(mb,nb)sum(V(mb)^2+V(nb)^2-2*V(mb)*V(nb)*cos(delta(mb)-delta(nb)))
objf =
#(mb,nb)sum(V(mb)^2+V(nb)^2-2*V(mb)*V(nb)*cos(delta(mb)-delta(nb)))
objf(1,2)
There you go (as far as all other variables and functions of this anonymous function are defined).
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I need to convert this:
[{"day"=>"2014-02-01", "users"=>1234},
{"day"=>"2014-02-02", "users"=>2234},
{"day"=>"2014-02-03", "users"=>3234},
{"day"=>"2014-02-04", "users"=>4234}]
into this:
[{:x=>1, y:=>1234},
{:x=>2, y:=>2234},
{:x=>3, y:=>3234},
{:x=>4, y:=>4234}]
a = [{"day"=>"2014-02-01", "users"=>1234}, {"day"=>"2014-02-02", "users"=>2234}, {"day"=>"2014-02-03", "users"=>3234}, {"day"=>"2014-02-04", "users"=>4234}]
a.map.with_index(1) { |h,i| { :x => i, :y => h['users'] } }
# => [{:x=>1, :y=>1234}, {:x=>2, :y=>2234}, {:x=>3, :y=>3234}, {:x=>4, :y=>4234}]
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about programming within the scope defined in the help center.
Closed 8 years ago.
Improve this question
I have a method from a long script that creates a hash from genetic sequences, however it is really messy and thus I was wondering whether there was a way to put it more elegantly.
Here is a sample of the script (i.e. it contains an example)...
def make_hash(motif)
main_hash = Hash.new
id = ">isotig00009_f2_3 ~: S.P. Cleavage Site: 22:23 - S.P. D-value: 0.532"
seq = "MLKCFSIIMGLILLLEIGGGCA~IYFYRAQIQAQFQKSLTDVTITDYRENADFQDLIDALQSGLSCCGVNSYEDWDNNIYFNCSGPANNPEALWCAFLLLYTGSSKRSSQHPVRLWSSFPRTTKYFPHKDLHHWLCGYVYNVD"
id_hash = Hash[[[:id_start, :id_end], id.split("~").map(&:strip)].transpose]
seq_hash = Hash[[[:signalp, :seq_end], seq.split("~").map(&:strip)].transpose]
signalp = seq_hash[:signalp]
new_seq_end = seq_hash[:seq_end].gsub(/#{motif}/, '<span class="motif">\0</span>')
new_seq_hash = Hash[:signalp => signalp, :new_seq_end => new_seq_end ]
main_hash[id_hash] = [new_seq_hash]
return main_hash
end
motif = "VT|QAQ|F.D"
main_hash = make_hash(motif)
main_hash.each do |id_hash, seq_hash|
puts id_hash[:id_start]
puts id_hash[:id_end]
puts seq_hash[0][:signalp]
puts seq_hash[0][:new_seq_end]
end
So Is there a more elegant way to write the make_hash method...
Many Thanks
I haven't tested this, but I think this simplification will work:
def make_hash(motif)
id = ">isotig00009_f2_3 ~: S.P. Cleavage Site: 22:23 - S.P. D-value: 0.532"
seq = "MLKCFSIIMGLILLLEIGGGCA~IYFYRAQIQAQFQKSLTDVTITDYRENADFQDLIDALQSGLSCCGVNSYEDWDNNIYFNCSGPANNPEALWCAFLLLYTGSSKRSSQHPVRLWSSFPRTTKYFPHKDLHHWLCGYVYNVD"
id_hash = Hash[[[:id_start, :id_end], id.split("~").map(&:strip)].transpose]
f, s = seq.split("~").map(&:strip)
s.gsub!(/#{motif}/, '<span class="motif">\0</span>')
new_seq_hash = Hash[Hash[:signalp, f], Hash[:new_seq_end, s]]
Hash[id_hash, new_seq_hash]
end
If (as it appears) id and seq both have constant values, you might consider breaking them apart manually, rather than with id.split("~").map(&:strip); i.e.,
id1 = ">isotig00009_f2_3
id2 = ": S.P. Cleavage Site: 22:23 - S.P. D-value: 0.532"
seq1 = "MLKCFSIIMGLILLLEIGGGCA"
seq2 = "IYFYRAQIQAQFQKSLTDVTITDYRENADFQDLIDALQSGLSCCGVNSYEDWDNNIYFNCSGPANNPEALWCAFLLLYTGSSKRSSQHPVRLWSSFPRTTKYFPHKDLHHWLCGYVYNVD"
If there were a need to make seq2 more readable, we could use the "line continuation" character, \ (which even works within strings) like this:
seq2 = "IYFYRAQIQAQFQKSLTDVTITDYRENADFQDLIDALQSGLSCCGVNSYEDWDNNIYFNC"\
"SGPANNPEALWCAFLLLYTGSSKRSSQHPVRLWSSFPRTTKYFPHKDLHHWLCGYVYNVD"
or this:
seq2 = "IYFYRAQIQAQFQKSLTDVTITDYRENADFQDLIDALQSGLSCCGVNSYEDWDNNIYFNC\
SGPANNPEALWCAFLLLYTGSSKRSSQHPVRLWSSFPRTTKYFPHKDLHHWLCGYVYNVD"
If you preferred, you could make 'id' and 'seq' constants ('ID' and 'SEQ', say) and move them outside the method definition. Not surprisingly, line continuation also works for constant strings.