Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Can not figure out my ? Subscripted assignment dimension mismatch-problem

  1. Aug 20, 2012 #1
    Can not figure out my ??? Subscripted assignment dimension mismatch-problem

    EDIT: This is Matlab code.

    Hello!

    I have some matlab code and I've run into a problem that I can't seem to be able to solve. I hope that someone might help me find a solution. Here is the error

    Code (Text):

    ??? Subscripted assignment dimension mismatch.

    Error in ==> simrun at 30
        [agenda(:,i) in out inagenda
        outagenda]=agendafunc(eventlist,tokendistr(:,i),i,inlist,outlist);

    Error in ==> main at 5
    simrun();
     
    And this is the code(omitted parts that I think are less important:)
    Code (Text):

    (...)
    for i=1:T
        [agenda(:,i) in out inagenda outagenda]=agendafunc(eventlist,tokendistr(:,i),i,inlist,outlist);
    (...)    
    end
    (...)
     
    Here agenda is a 150x600 array, T=600, in and out are doubles, inagenda and outagenda are both 150x1 arrays, eventlist is a 150x600 array, tokendistr is a 150x600 array, inlist and outlist are both 150x600 arrays. popsize=150.

    The agendafunc() function is this:
    Code (Text):


    function[agendatoday in out inagenda outagenda]=agendafunc(eventlist,tokenstoday,dayno,inlist,outlist)
    global tokentreshold popsize p3
    agendatoday=zeros(popsize,1);
    in=0;out=0;
    inagenda=zeros(popsize,1);
    outagenda=zeros(popsize,1);
    for i=1:popsize
        %comments
        if(tokenstoday(i)>tokentreshold)
            if(eventlist(i,dayno)==1)
                agendatoday(i)=1; % comments
                out=out+1;
                outagenda(i)=out;
            else if(eventlist(i,dayno)==2 || eventlist(i,dayno)==0)
                    agendatoday(i,dayno)=0; % comments
                else
                    agendatoday(i,dayno)=0; % comments
                end
            end
        else if(tokenstoday(i)==0)
                %comments
                if(eventlist(i,dayno)==2)
                    agendatoday(i)=2;
                    in=in+1;
                    inagenda(i)=in;
                else
                    a=rand;
                    if(p3<a)
                        agendatoday(i)=2;   % comments
                        %comments
                        in=in+1;
                        inagenda(i)=in;
                    end
                end
            else if(check(tokenstoday,outlist,inlist,dayno)==true)
                    %comments
                    if(eventlist(i,dayno)==2)
                        agendatoday(i)=2;
                        in=in+1;
                        inagenda=in;
                    else if(eventlist(i,dayno)==1)
                            agendatoday(i)=1;
                            out=out+1;
                            outagenda(i)=out;
                        else if(eventlist(i,dayno==0))
                                a=rand;
                                if(p3<a)
                                    agendatoday(i)=2;   % comments,
                                    %comments
                                    in=in+1;
                                    inagenda(i)=in;
                                end
                            end
                        end
                    end
                else
                    %comments
                    if(eventlist(i,dayno)==1)
                        agendatoday(i)=1;
                        out=out+1;
                        outagenda(i)=out;
                    else if(eventlist(i,dayno)==2)
                            agendatoday(i)=2;
                            in=in+1;
                            inagenda(i)=in;
                        else
                            agendatoday=0;
                        end
                    end
                end
            end
        end
    end
    end

     
    where I think the most important part is that I never change the size of any array. I also ommitted my comments here.

    I have no idea what went wrong, as the array sizes I believe to be of correct size. The error takes place the second run of the loop, i.e. i=2 in the first for loop in the middle code window of this page. Does anyone have a tip for me what I could be missing or why Matlab finds an error?

    Thanks a lot.
     
    Last edited: Aug 20, 2012
  2. jcsd
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Can you offer guidance or do you also need help?
Draft saved Draft deleted



Similar Discussions: Can not figure out my ? Subscripted assignment dimension mismatch-problem
Loading...