From: Virtualized on 21 Nov 2009 16:12 Hi Everybody I have the following simple script: if P(1) == 0 return; else P1=P(1) if P(2) == 0 return; else P2=P(2) if P(3) == 0 return; else P3=P(3) end end end If i don't have any value at any location of the matrix or if the value is "0" then i want the program to stop executing. Suppose i have P=[1,2 ]; Here i have only two values for P(1) and P(2) so when i execute script then i get the following error: ??? Attempted to access P(3); index out of bounds because numel(P)=2. Error in ==> p at 13 if P(3) == 0 Any help in this regard is highly appreciated. Regards
From: MatlabFCT NG on 21 Nov 2009 16:43 Could you please structure better your script? On 21 Nov, 21:12, Virtualized <razzaqa...(a)gmail.com> wrote: > Hi Everybody > > I have the following simple script: > > if P(1) == 0 > return; > else > P1=P(1) > > if P(2) == 0 > return; > else > P2=P(2) > > if P(3) == 0 > return; > else > P3=P(3) > end > end > end > > If i don't have any value at any location of the matrix or if the > value is "0" then i want the program to stop executing. > > Suppose i have > > P=[1,2 ]; > > Here i have only two values for P(1) and P(2) so when i execute script > then i get the following error: > > ??? Attempted to access P(3); index out of bounds because numel(P)=2. > > Error in ==> p at 13 > if P(3) == 0 > > Any help in this regard is highly appreciated. > > Regards
From: Virtualized on 21 Nov 2009 17:11 On Nov 21, 10:43 pm, MatlabFCT NG <matfc...(a)gmail.com> wrote: > Could you please structure better your script? > > On 21 Nov, 21:12, Virtualized <razzaqa...(a)gmail.com> wrote: > > > > > Hi Everybody > > > I have the following simple script: > > > if P(1) == 0 > > return; > > else > > P1=P(1) > > > if P(2) == 0 > > return; > > else > > P2=P(2) > > > if P(3) == 0 > > return; > > else > > P3=P(3) > > end > > end > > end > > > If i don't have any value at any location of the matrix or if the > > value is "0" then i want the program to stop executing. > > > Suppose i have > > > P=[1,2 ]; > > > Here i have only two values for P(1) and P(2) so when i execute script > > then i get the following error: > > > ??? Attempted to access P(3); index out of bounds because numel(P)=2. > > > Error in ==> p at 13 > > if P(3) == 0 > > > Any help in this regard is highly appreciated. > > > Regards Hi I am writing it again. The script is: if P(1) == 0 return; else P1=P(1) if P(2) == 0 return; else P2=P(2) if P(3) == 0 return; else P3=P(3) end end end
From: Virtualized on 21 Nov 2009 17:15 On Nov 21, 10:43 pm, MatlabFCT NG <matfc...(a)gmail.com> wrote: > Could you please structure better your script? > > On 21 Nov, 21:12, Virtualized <razzaqa...(a)gmail.com> wrote: > > > > > Hi Everybody > > > I have the following simple script: > > > if P(1) == 0 > > return; > > else > > P1=P(1) > > > if P(2) == 0 > > return; > > else > > P2=P(2) > > > if P(3) == 0 > > return; > > else > > P3=P(3) > > end > > end > > end > > > If i don't have any value at any location of the matrix or if the > > value is "0" then i want the program to stop executing. > > > Suppose i have > > > P=[1,2 ]; > > > Here i have only two values for P(1) and P(2) so when i execute script > > then i get the following error: > > > ??? Attempted to access P(3); index out of bounds because numel(P)=2. > > > Error in ==> p at 13 > > if P(3) == 0 > > > Any help in this regard is highly appreciated. > > > Regards Sorry for the previous post. I am going to rewrite it again: if P(1) == 0 return; else P1=P(1); if P(2) == 0 return; else P2=P(2) if P(3) == 0 return; else P3=P(3) end end end When i give it the following vector as input: P=[1,2 ]; I get the following error: ??? Attempted to access P(3); index out of bounds because numel(P)=2. Error in ==> p at 13 if P(3) == 0 Thank you for your response. Regards
From: Pedro Manuel on 21 Nov 2009 17:46 Hi Virtualized, Here is your code: P=[1,2]; if P(1) == 0 return; else P1=P(1); if P(2) == 0 return; else P2=P(2); if P(3) == 0 %problem in this line return; else P3=P(3); end end end Your problem is in the line 13, there you are asking a question to computer: is P(3) equal to 0? However you don't have in your matrix any value in that position, therefore the computer doesn't have any number to compare... and that's why you have the error... If you change your matrix P to P=[1,2,3], you'll not have any problem... Virtualized <razzaqadil(a)gmail.com> wrote in message <346ea9a3-b20a-497b-a4eb-dab001daf391(a)k4g2000yqb.googlegroups.com>... > On Nov 21, 10:43?pm, MatlabFCT NG <matfc...(a)gmail.com> wrote: > > Could you please structure better your script? > > > > On 21 Nov, 21:12, Virtualized <razzaqa...(a)gmail.com> wrote: > > > > > > > > > Hi Everybody > > > > > I have the following simple script: > > > > > if P(1) == 0 > > > ? ? ? ? ?return; > > > ? ? ?else > > > ? ? ? ? ?P1=P(1) > > > > > ? ? ?if P(2) == 0 > > > ? ? ? ? ?return; > > > ? ? ?else > > > ? ? ? ? ?P2=P(2) > > > > > ? ? ? ? ?if P(3) == 0 > > > ? ? ? ? ?return; > > > ? ? ?else > > > ? ? ? ? ?P3=P(3) > > > ? ? ?end > > > ? ? ? ? ?end > > > ? ? ?end > > > > > If i don't have any value at any location of the matrix or if the > > > value is "0" ?then i want the program to stop executing. > > > > > Suppose i have > > > > > P=[1,2 ]; > > > > > Here i have only two values for P(1) and P(2) so when i execute script > > > then i get the following error: > > > > > ??? Attempted to access P(3); index out of bounds because numel(P)=2. > > > > > Error in ==> p at 13 > > > ? ? ? ? ?if P(3) == 0 > > > > > Any help in this regard is highly appreciated. > > > > > Regards > > Sorry for the previous post. I am going to rewrite it again: > > if P(1) == 0 > return; > else > P1=P(1); > > if P(2) == 0 > return; > else > P2=P(2) > > if P(3) == 0 > return; > else > P3=P(3) > end > > end > > end > > > When i give it the following vector as input: > > P=[1,2 ]; > > I get the following error: > > ??? Attempted to access P(3); index out of bounds because numel(P)=2. > > Error in ==> p at 13 > if P(3) == 0 > > > Thank you for your response. > > Regards
|
Next
|
Last
Pages: 1 2 Prev: amdf Next: Is there any mechanism to terminate simulink from inside simulink? |