Got Questions? Get Answers.
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:
Error message

Subject: Error message

From: Diego Zegarra

Date: 20 Oct, 2008 22:51:01

Message: 1 of 5

I am having the following problem, when I run my code it shows me this error.

??? Error using ==> le
Matrix dimensions must agree.

What does this error mean? Let me know if you want me to show my code to find the problem. Thanks in advance!

Subject: Error message

From: Walter Roberson

Date: 20 Oct, 2008 23:15:22

Message: 2 of 5

Diego Zegarra wrote:
> I am having the following problem, when I run my code it shows me this error.
 
> ??? Error using ==> le
> Matrix dimensions must agree.
]
> What does this error mean?

'le' is the name of the routine that the problem was found in. 'le' is the "word"
name of the routine that is executed for the '<=' operator.

So you have an expression of the form A <= B and the two sides are not
the same size: they either have a different number of elements, or the
elements are arranged differently (e.g., a 4 x 2 matrix instead of a 2 x 4 matrix.)

Subject: Error message

From: Diego Zegarra

Date: 20 Oct, 2008 23:17:01

Message: 3 of 5

This is the code, I guess the error means there is a problem with the less than or equal but I cant figure it out.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
clear all

% Get the text file given and extract data from it
% Create an array to store the Machine Total Times
% Replicate the Processing Time for each machine and add it % to the Setup Time
fgetmat;
MTT = cell(numMachines,1);
for idx = 1:numMachines
    MTT{idx} = repmat(PT(:,idx)',[numJobs 1]) + ST{idx}
end

% Create a cell array for the MIN & POS and MAX & POS
% Create a cell array to store the Machine schedule
% Create a cell array to store the Machine time
minpos = cell(numMachines,1);
maxpos = cell(numMachines,1)
MSchJ = cell(numMachines,1);
MSchT = cell(numMachines,1);
eligibleIdxs = cell(numMachines,1);

% Initialize the values for %p and %r
p = 0.20;
r = 0.40;

% Finding the MIN & MAX value for starting time at machine
% Assumes that the starting time of each job is the diagonal
% "a" returns the value and "b" returns the column
for n = 1:numMachines;
    M = MTT{n};
    [a b] = min(diag(M));
    minpos{n} = [a b];
    [A B] = max(diag(M));
    maxpos{n} = [A B];
end

% Change the array minpos & maxpos to a matrix to get out
% values easier
MINP = cell2mat(minpos);
MAXP = cell2mat(maxpos);
rand('state', sum(100*clock));

while min(MINP) ~= Inf;
    if rand < p;
        [a b] = min(MINP(:,1)); % Get the MIN time
        MSchT{b} = [MSchT{b} a];
        MSchJ{b} = [MSchJ{b} MINP(b,2)];

    % Putting Inf at the diag for the selected machine
        MTT{b} = inf_diag(MTT{b});
    % Putting Inf at the columns for the job number
        for c = 1:numMachines;
            MTT{c}(:,MINP(b,2)) = Inf;
        end
    % Putting Inf at the rows for the job number except
    % machine b
        for d = [1:b-1 b+1:numMachines];
            MTT{d}(MINP(b,2),:) = Inf;
        end
    % Finding the minimum starting values again
        for n = 1:numMachines;
            M = MTT{n};
            [a b] = min(diag(M));
            minpos{n} = [a b];
            [A B] = max(diag(M));
            maxpos{n} = [A B];
        end
        MINP = cell2mat(minpos);
        MAXP = cell2mat(maxpos);
    else
        [a b] = min(MINP(:,1));
        [A B] = max(MAXP(isfinite(MAXP(:,1)),1));

        for m = 1:numMachines;
            diags{m,1} = diag(MTT{m});
            vmax = a + floor(r*(A-a));
            eligibleEntry = (diags{m,1} <= vmax);
            eligibleIdxs{m} = find(eligibleEntry(:));
        end

        selMach = floor(rand*numMachines+1);
        selIdx = floor(rand*size(eligibleIdxs{selMach},1)+1);
        idxVal = eligibleIdxs{selMach}(selIdx);
        rndTim = diag(MTT{selMach}(idxVal,idxVal));
  
        MSchT{selMach} = [MSchT{selMach} rndTim];
        MSchJ{selMach} = [MSchJ{selMach} idxVal];
    % Putting Inf at the diag for the selected machine
        MTT{selMach} = inf_diag(MTT{selMach});
    % Putting Inf at the columns for the job number
        for c = 1:numMachines;
            MTT{c}(:,idxVal) = Inf;
        end
    % Putting Inf at the rows for the job number except
    % machine b
        for d = [1:selMach-1 selMach+1:numMachines];
            MTT{d}(idxVal,:) = Inf;
        end
    % Finding the minimum starting values again, now with one less job to
    % select and then putting them together in one matrix
        for n = 1:numMachines;
            M = MTT{n};
            [a b] = min(diag(M));
            minpos{n} = [a b];
            [A B] = max(diag(M));
            maxpos{n} = [A B];
        end
        MINP = cell2mat(minpos);
        MAXP = cell2mat(maxpos);
    end
end

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

Thanks in advance!

Subject: Error message

From: Diego Zegarra

Date: 21 Oct, 2008 01:11:03

Message: 4 of 5

I know that the problem is in these couple lines but I am having trouble fixing it,

       for m = 1:numMachines;
            diags{m,1} = diag(MTT{m});
            vmax = a + floor(r*(A-a));
  *** eligibleEntry = (diags{m,1} <= vmax);
            eligibleIdxs{m} = find(eligibleEntry(:));
       end

The first time it goes through works fine but then it messes up because for one of the machine there are not going to be any eligible entries since all of them will be Inf. I know it is somewhere in here but I do not know what it is.

Basically once it goes through the while loop the second or third time depending on the random number generated, eligible entry for one of the machines will give all zeros and then when trying to find eligible entries there are none.

Help will be very much appreciated!

Subject: Error message

From: Walter Roberson

Date: 21 Oct, 2008 06:24:52

Message: 5 of 5

Diego Zegarra wrote:
> I know that the problem is in these couple lines but I am having trouble fixing it,

> for m = 1:numMachines;
> diags{m,1} = diag(MTT{m});
> vmax = a + floor(r*(A-a));
> *** eligibleEntry = (diags{m,1} <= vmax);
> eligibleIdxs{m} = find(eligibleEntry(:));
> end

With the information shown to us, there are only a small number of ways
that section of code could produce the error message you cited earlier
about 'le' and dimension mismatch.

1) You provided your own function named 'le' that is overriding the
built-in 'le' function; or

2) At least one of the variables A, a, or r is a non-scalar vector or
array, and that array is not a 1 x N vector of the same length as the
diagonal of at least one of the MTT arrays; or

3) At leats one of the variables A, a, or r is a non-scalar vector or
array, and that array is not the same shape as is returned by
the function named 'diag' that you have provided that overrides the
built-in 'diag' function.

If none of these cases hold, then the error you are experiencing is not
in the lines you have shown. In particular, eligibleEntry coming out all
logical 0's for some MTT{m} matrix does *not* cause any problem for the code
that you show (though it could, of course, lead to problems in code you
do not show.)


Suggestion: vmax = a + floor(r*(A-a)); is constructed entirely from values
that never change within the loop code you show. Therefore, vmax could be
calculated once before the beginning of the loop instead of being calculated
at each iteration of the loop.

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