Error in find command....

t=linspace(xq(1),xq(np),1001)
y2=polyval(pmon,t)
plot(t,y2,'k--',x)
for j=1:6
for i=1:1001;
t1(j)=find(y2(i)=pmon(j))
end
end
i want to find value of t(x axis) for which value of pmon(y axis) is given ??

2 commentaires

shoaib Ch
shoaib Ch le 14 Mar 2019
it is not giving me value for t , i want to use it for finding roots
Adam Danz
Adam Danz le 14 Mar 2019
Have you implemented the correction suggested in the answers section below?
If you've implemented that correction and 't' is empty, that means there were no matches between y2(i) and pmon(i).

Connectez-vous pour commenter.

Réponses (1)

Adam Danz
Adam Danz le 14 Mar 2019

0 votes

One equal sign assigns a value to a variable.
Two equal signs perfoms a comparison between A and B and returns a logical value.
t1(j) = find(y2(i) = pmon(j)) %incorrect
t1(j) = find(y2(i) == pmon(j)) %correct

12 commentaires

shoaib Ch
shoaib Ch le 14 Mar 2019
MATLAB R2016a.jpg
yup it says dimension mismatches , i think bec of too much values after point , how can i fix uptill one decimal place??
madhan ravi
madhan ravi le 14 Mar 2019
Remember you are dealing with float numbers so add tolerance.
Adam Danz
Adam Danz le 14 Mar 2019
Please provide the full copy-pasted error message and relevant code that produces the error.
shoaib Ch
shoaib Ch le 14 Mar 2019
pos_a = -0.07 0.82 0 -4.03 %values i want to compare
for k=1:pos_a
if pos_a(k)>= pos_a(k)+1
s0=t(pos_a(k))% ..statements to get the root in t(pos a(i)) to t(pos a(i+1))
s1=t(pos_a(k)+1)
else
s1=t(pos_a(k)) % ..statements to get the root in t(pos a(i)) to t(pos a(i+1))
s0=t(pos_a(k)+1)
end
end
as i mention t is array cotaining x values and pos_a is array containing y values at some unknown x values
t=linspace(xq(1),xq(np),1001)
i make a function to show which valve of t gives me value of pos_a (not direct but in approximate) and thanx in advance
Adam Danz
Adam Danz le 14 Mar 2019
There must be a mistake with the code you provided.
1) the first line causes an error because the vector is not enclosed in [brackets].
2) the loop k=1:pos_a, pos_a is a vector, not an integer.
Adam Danz
Adam Danz le 14 Mar 2019
if pos_a(k)>= pos_a(k)+1
How would this ever be true?
shoaib Ch
shoaib Ch le 15 Mar 2019
i use if command to check weather it is true or not other wse will go for elese command .... is there be any command in matlab which gives me interval values of t (x axix) on basis of y value , meanx your x value lies with in this intervalval of x??
Adam Danz
Adam Danz le 15 Mar 2019
I understand how the 'if' command works. What I don't understand is what you're trying to do with it. Your statement
if pos_a(k)>= pos_a(k)+1
is analogous to
if x >= x+1
which would never be the case.
Did you mean to this?
if pos_a(k)>= pos_a(k+1)
Sorry, I don't understand your last question above.
shoaib Ch
shoaib Ch le 15 Mar 2019
yup the last ones but it does not gives me the value bec of decimal places as two values are not exectly same , and if you go for greater value it gives you all values that are greater than this
Adam Danz
Adam Danz le 15 Mar 2019
Please provide a minimal working example so I can reproduce your problem.
shoaib Ch
shoaib Ch le 15 Mar 2019
xq=[ -3, -2, -1, 2, 6, 7];
yq=[ 1, -2, 1, -2, 2, -2];
pmon=[-61/840, 49/60, -1663/840, -1693/420, 169/15, 73/7]; %interpolation values
t=linspace(xq(1),xq(6),1001) %values of xq
y2=polyval(pmon,t)
plot(t,y2,'k--')
Now i want to chect weather there exist a root between pmon values ,next program give me root values
for i=1:5;
if pmon(i)<0 & pmon(i+1)>0
pos_a(i)=pmon(i)
elseif pmon(i)>0 & pmon(i+1)<0
pos_a(i)=pmon(i)
else
end
now , pos_a is values of y axis and i want to find what be the values of t (x values) which give me these y values according to data ... for this i use that code but its not working
for i=1:5;
if pos_a(i)>= pos_a(i+1)
s0=t(pos_a(i))% ..statements to get the root in t(pos a(i)) to t(pos a(i+1))
s1=t(pos_a(i+1))
else
s1=t(pos_a(i)) % ..statements to get the root in t(pos a(i)) to t(pos a(i+1))
s0=t(pos_a(i+1))
end
end
And and Thanx again for your Kindness
shoaib Ch
shoaib Ch le 15 Mar 2019
Figure 1.jpg
if these be pos_a values than what be t values ??

Connectez-vous pour commenter.

Catégories

En savoir plus sur Medical Physics dans Centre d'aide et File Exchange

Question posée :

le 14 Mar 2019

Modifié(e) :

le 2 Avr 2019

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by