Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4058834
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T15:07:47+00:00 2026-05-20T15:07:47+00:00

Hye guys. Okay. I have done this coding. But it seems have error. Can

  • 0

Hye guys. Okay. I have done this coding. But it seems have error. Can anyone explain to me why there is an error? This is the coding:

Hcurve = cell2mat(get(handles.Mytable3,'Data'));
costA = cell2mat(get(handles.Mytable1,'Data'));
cost1 = str2num(get(handles.input2_editText,'String'));
cost2 = str2num(get(handles.input3_editText,'String'));
cost3 = str2num(get(handles.input4_editText,'String'));
cost4 = str2num(get(handles.input5_editText,'String'));
limit = cell2mat(get(handles.Mytable2,'Data'));
Pdt = str2num(get(handles.input1_editText,'String'));

if isempty(costA)

    if size(Hcurve,1) == 2

        H1 = Hcurve(1,:)*cost1;
        H2 = Hcurve(2,:)*cost2;
        H = num2cell([H1;H2]);
        set(handles.Mytable1,'Data',H)
        cost = cell2mat(get(handles.Mytable1,'Data'));

    else if size(Hcurve,1) == 3 

        H1 = Hcurve(1,:)*cost1;
        H2 = Hcurve(2,:)*cost2;
        H3 = Hcurve(3,:)*cost3;
        H = num2cell([H1;H2;H3]);
        set(handles.Mytable1,'Data',H)
        cost = cell2mat(get(handles.Mytable1,'Data'));

    else if size(Hcurve,1) == 4 

        H1 = Hcurve(1,:)*cost1;
        H2 = Hcurve(2,:)*cost2;
        H3 = Hcurve(3,:)*cost3;
        H4 = Hcurve(3,:)*cost4;
        H = num2cell([H1;H2;H3;H4]);
        set(handles.Mytable1,'Data',H)
        cost = cell2mat(get(handles.Mytable1,'Data'));

        else 

        cost = costA;

        end
        end
    end
end


if size(cost,1) == 1

    set(handles.text8,'String','At Lease Two Generators');

This is the error occured:

??? At compilation, “cost” was determined to be a variable and this
variable is uninitialized. “cost” is also a function name and previous versions
of MATLAB would have called the function.
However, MATLAB 7 forbids the use of the same name in the same
context as both a function and a variable.

Error in ==> fyp_editor>Mybutton_Callback at 131
if size(cost,1) == 1

Error in ==> gui_mainfcn at 96
feval(varargin{:});

Error in ==> fyp_editor at 42
gui_mainfcn(gui_State, varargin{:});

Error in ==>
@(hObject,eventdata)fyp_editor(‘Mybutton_Callback’,hObject,eventdata,guidata(hObject))

??? Error while evaluating uicontrol Callback

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T15:07:48+00:00Added an answer on May 20, 2026 at 3:07 pm

    The likely problem you’re having is that costA is not empty, so none of your nested code gets evaluated and the variable cost will never be initialized to anything before you call the line if size(cost,1) == 1. You probably want to order your nested if statements something like this:

    if isempty(costA)  %# If costA is empty, compute a value for cost
    
      if size(Hcurve,1) == 2
      ...
      elseif size(Hcurve,1) == 3
      ...
      elseif size(Hcurve,1) == 4
      ...
      end
    
    else
      cost = costA;  %# Will set cost equal to costA if it is not empty
    end
    

    The explanation for the unusual error you’re getting is that cost appears in your code as a variable, but there appears to be a function with the name cost as well. When you define a variable with the same name as a function, the variable takes precedence and will be used instead of the function whenever that name is used in any computations.

    Even though cost doesn’t get initialized to anything in your condition, MATLAB still recognizes that it could be a variable in your function and thus (in MATLAB 7 or newer) it doesn’t try to call the function cost. Apparently, in older versions MATLAB would call the shadowed function in the event that a variable by the same name is uninitialized.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

hye guys.. i have a problem where i did'nt knw what the error i
Hye guys, I installed a wufoo form on one of my websites. It links
Hye Guys, I'm busy working on a time series and am trying to find
Hye guys, I included a screenshot to help clarify my problem: http://i40.tinypic.com/mcrnmv.jpg . I'm

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.