Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Matlab GUI code - zeros

Subject: Matlab GUI code - zeros

From: AP

Date: 3 Aug, 2010 19:48:06

Message: 1 of 7

I've started working with the GUI in Matlab, and at several places in my code, I use a a 'blank' column vector with the zeros function

e.g. Val = zeros(2*N+1,1)

and this goes on producing errors, either at this point or later.

How should I enter this in a GUI? It works fine as an ordinary function.

Thanks.

Subject: Matlab GUI code - zeros

From: Sean

Date: 3 Aug, 2010 19:54:04

Message: 2 of 7

"AP " <apb1508138@gmail.com> wrote in message <i39rpm$9gq$1@fred.mathworks.com>...
> I've started working with the GUI in Matlab, and at several places in my code, I use a a 'blank' column vector with the zeros function
>
> e.g. Val = zeros(2*N+1,1)
>
> and this goes on producing errors, either at this point or later.
>
> How should I enter this in a GUI? It works fine as an ordinary function.
>
> Thanks.

What are the errors?

Subject: Matlab GUI code - zeros

From: Jan Simon

Date: 3 Aug, 2010 21:30:25

Message: 3 of 7

Dear AP,

> I've started working with the GUI in Matlab, and at several places in my code, I use a a 'blank' column vector with the zeros function
>
> e.g. Val = zeros(2*N+1,1)
>
> and this goes on producing errors, either at this point or later.
> How should I enter this in a GUI? It works fine as an ordinary function.

How can the definition of a variable produce errors "later"?
How do you "enter" the definition of the variable in a GUI?
It is always a good idea to post the error message, because Matlab creates meaningful messages which explain how the problem can be solved.

Kind regards, Jan

Subject: Matlab GUI code - zeros

From: AP

Date: 3 Aug, 2010 21:36:04

Message: 4 of 7

"Sean " <sean.dewolski@nospamplease.umit.maine.edu> wrote in message <i39s4s$2f6$1@fred.mathworks.com>...
> "AP " <apb1508138@gmail.com> wrote in message <i39rpm$9gq$1@fred.mathworks.com>...
> > I've started working with the GUI in Matlab, and at several places in my code, I use a a 'blank' column vector with the zeros function
> >
> > e.g. Val = zeros(2*N+1,1)
> >
> > and this goes on producing errors, either at this point or later.
> >
> > How should I enter this in a GUI? It works fine as an ordinary function.
> >
> > Thanks.
>
> What are the errors?

Initially ---

"Warning: Size vector should be a row vector with integer elements. "

and

"??? Attempted to access OptVal(1.4); index must be a positive integer or logical."

(the latter part of my code is:


Vals = zeros(2*N+1,1)
Vals(1) = SO*d^N
for i = 2:2*N+1
     Vals(i) = u*Vals(i-1)
end
OptVal = zeros (2*N+1,1)
for i = 1:2:2*N+1
    OptVal(i) = max(SVals(i)-K,0)
end
for t=1:N
  for i= (t+1):2: (2*N+1-t)
    OptVal(i) = p_u*OptVal(i+1) + p_d*OptVal(i-1)
end
end
price = OptVal(N+1)
p = num2str(price)
set(handles.answer,'String',price);
guidata(hObject, handles);

Subject: Matlab GUI code - zeros

From: Walter Roberson

Date: 3 Aug, 2010 21:52:18

Message: 5 of 7

AP wrote:
> "Sean " <sean.dewolski@nospamplease.umit.maine.edu> wrote in message
> <i39s4s$2f6$1@fred.mathworks.com>...
>> "AP " <apb1508138@gmail.com> wrote in message
>> <i39rpm$9gq$1@fred.mathworks.com>...
>> > I've started working with the GUI in Matlab, and at several places
>> in my code, I use a a 'blank' column vector with the zeros function >
>> > e.g. Val = zeros(2*N+1,1)
>> > > and this goes on producing errors, either at this point or later.
>> > > How should I enter this in a GUI? It works fine as an ordinary
>> function. > > Thanks.
>> What are the errors?
>
> Initially ---
>
> "Warning: Size vector should be a row vector with integer elements. "
>
> and
> "??? Attempted to access OptVal(1.4); index must be a positive integer
> or logical."

Are you sure that N is an integer?

Subject: Matlab GUI code - zeros

From: AP

Date: 3 Aug, 2010 22:08:05

Message: 6 of 7

Yes, I checked it by setting values for the variables within the program (i.e. N =5, K= 4, etc.) to see if it was a probalem involving my textboxes on the GUI. But I get the same error.

Walter Roberson <roberson@hushmail.com> wrote in message <i3a3ap$ibs$1@canopus.cc.umanitoba.ca>...
> AP wrote:
> > "Sean " <sean.dewolski@nospamplease.umit.maine.edu> wrote in message
> > <i39s4s$2f6$1@fred.mathworks.com>...
> >> "AP " <apb1508138@gmail.com> wrote in message
> >> <i39rpm$9gq$1@fred.mathworks.com>...
> >> > I've started working with the GUI in Matlab, and at several places
> >> in my code, I use a a 'blank' column vector with the zeros function >
> >> > e.g. Val = zeros(2*N+1,1)
> >> > > and this goes on producing errors, either at this point or later.
> >> > > How should I enter this in a GUI? It works fine as an ordinary
> >> function. > > Thanks.
> >> What are the errors?
> >
> > Initially ---
> >
> > "Warning: Size vector should be a row vector with integer elements. "
> >
> > and
> > "??? Attempted to access OptVal(1.4); index must be a positive integer
> > or logical."
>
> Are you sure that N is an integer?

Subject: Matlab GUI code - zeros

From: Jan Simon

Date: 3 Aug, 2010 22:54:22

Message: 7 of 7

Dear AP,

> > Are you sure that N is an integer?

> Yes, I checked it by setting values for the variables within the program (i.e. N =5, K= 4, etc.) to see if it was a probalem involving my textboxes on the GUI. But I get the same error.

No. N is not integer in your program, as Walter said already. Anywhere in the code N is overwritten by a floating point value. Perhaps by "N = ...", "eval('N = ..." or by "load MatFile", if the MatFile contains the variable N. Anyhow, N is not integer anymore.
Please use the debugger to stop the program, when the problem occurs:
  dbstop if error
Then display the value of N in the command window.

Good luck, Jan

Tags for this Thread

No tags are associated with this thread.

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us