|
On Nov 21, 11:47 pm, "Pedro Manuel " <matfc...@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...@gmail.com> wrote in message <346ea9a3-b20a-497b-a4eb-dab001daf...@k4g2000yqb.googlegroups.com>...
> > On Nov 21, 10:43?pm, MatlabFCT NG <matfc...@gmail.com> wrote:
> > > Could you please structure better your script?
>
> > > On 21 Nov, 21:12, Virtualized <razzaqa...@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
|