From: Pedro Manuel on 21 Nov 2009 17:47 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
From: Virtualized on 21 Nov 2009 18:05 On Nov 21, 11:47 pm, "Pedro Manuel " <matfc...(a)gmail.com> wrote: > 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 <razzaqa...(a)gmail.com> wrote in message <346ea9a3-b20a-497b-a4eb-dab001daf...(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 Hi Yes i know that. But as i stated in my first message, i want to check both conditions if (1) either P(3) or P(2) or P(1) == 0 or (2) there is no value at any location then program should execute the "return" statement. Thank you once again for your help. Regards
From: Pedro Manuel on 21 Nov 2009 18:40 Hi again :), Even if you don't have any matrix P, you want to make your program return... Is that it? Maybe you can use try catch, is not a fancy way to do it. I'm sorry but i don't remember other now. ********************** try % your code catch return end **********************
From: Jan Simon on 22 Nov 2009 06:55 Dear Virtualized! > Yes i know that. But as i stated in my first message, i want to check > both conditions if > (1) either P(3) or P(2) or P(1) == 0 or > (2) there is no value at any location Do you mean: if ~all(P) || length(P) < 3 return; end Kind regards, Jan
From: Virtualized on 22 Nov 2009 07:21 On Nov 22, 12:55 pm, "Jan Simon" <matlab.THIS_Y...(a)nMINUSsimon.de> wrote: > Dear Virtualized! > > > Yes i know that. But as i stated in my first message, i want to check > > both conditions if > > (1) either P(3) or P(2) or P(1) == 0 or > > (2) there is no value at any location > > Do you mean: > if ~all(P) || length(P) < 3 > return; > end > > Kind regards, Jan Dear Jan Thanks a lot. Yes that is exactly what i wanted to achieve. Best Regards
First
|
Prev
|
Pages: 1 2 Prev: amdf Next: Is there any mechanism to terminate simulink from inside simulink? |