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

  • SEARCH
  • Home
  • 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 9068601
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T17:13:50+00:00 2026-06-16T17:13:50+00:00

I have written this messy code. When I run the first part of the

  • 0

I have written this messy code. When I run the first part of the code using the function daa, some times it produces a result, but sometimes it produces an error message. Does anyone have some ideas how to correct it?

Improper assignment with rectangular empty matrix.
Error in daa (line 26)
favoritec(i)=find(sPref(i,:)==bestmatch(i));

It’s especially a problem, when I increased the dimension of n and m

This is the code

clear all;
n=4;
m=2;
Q=[1;1];
sPref=zeros(n,m);
cPref=zeros(m,n);
for i=1:n
sPref(i,:)=randperm(m);
end
for j=1:m
cPref(j,:)=randperm(n);
end
match=daa(sPref,cPref,Q)

Then the function daa is defined as following:

function match=daa(sPref,cPref,Q)
proposition=false(size(sPref));    % keep track who has proposed to which. False= not proposed yet
match=zeros(length(sPref),1);
favoritec=zeros(length(sPref),1);
numberS=zeros(size(cPref,1),1);
bestmatch=zeros(length(sPref),1);
iter=0;
 while (min(match)==0)      % as long as there is one unmatched, continues the loop (except the break)
iter=iter+1;

app=find(match==0);
for i=app(1:end)'
    notProposed=(proposition(i,:)==false);
    bestmatch(i)=min(sPref(i,notProposed));
    favoritec(i)=find(sPref(i,:)==bestmatch(i));
    numberS(favoritec(i))= numberS(favoritec(i))+1;    % keep track of the no.of applicants
    proposition(i,bestmatch(i))=1;   % propsed to college j finishes,either reject or accept
end

% college deciding...
for j=1:size(cPref,1)
    S_comp=find(favoritec==j);   % find the students competing for the same Favoritec
    if numberS(j) <=Q(j)       % sum of students at the college smaller or equal than quota
    match(S_comp)=favoritec(S_comp);               % accept tentative offer
    numberS(j)=sum(match==j);
    sPref(S_comp,j)=NaN;
    else 
        noapl=setxor(1:length(cPref),S_comp);
        cPreft=cPref(j,:);          % truncated pref,change the pref of those who didn't apply to NaN
        cPreft(noapl)=NaN;           
        [r,I]=sort(cPreft);    
        topq=I(1:Q(j));                    % college takes the top quota q students
        match(S_comp)=0;                           % clean the previous assignment
        match(topq)= favoritec(topq);
        numberS(favoritec)=Q(j);
        rejapp=setxor(S_comp,topq);     % the students who got rejected
        sPref(rejapp,j)=NaN;
    end
    %display(match);
end
%% if all choices have proposed, then stop
 if proposition(i,:)==true;
        display('already proposed to every college')
        display(i)
        break
 end
 end
  • 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-06-16T17:13:52+00:00Added an answer on June 16, 2026 at 5:13 pm

    Background

    I believe that ‘Improper assignment with rectangular empty matrix’ means that you tried to assign a rectangular empty matrix to a scalar location. A rectangular empty matrix is a matrix that displays as “Empty matrix: 0-by-1”. One way to generate such a matrix is to do a find on a matrix that is all false or that is a rectangular empty matrix itself.

    Answer

    In your code, this error occurs because there were no instances where sPref(i,:)==bestmatch(i).

    If you type

    rng(1237)
    

    And then execute your code (without the clear all). You can reproduce the error.

    Looking at the variables just before daa is called, you can see that daa([2, 1; 2, 1; 1, 2; 2, 1], [2, 1, 3, 4; 4, 2, 1, 3], [1;1]) fails. Another breakpoint reveals that sPref(1,:) = [2,NaN] and that notProposed=[false, true] so bestmatch(1) is NaN – which is never equal to anything. This indicates that the bug likely lies in how you assign NaNs to sPref in the next section.

    You’ll need to find that bug yourself. But this should answer your question about the ‘improper assignment’ error.

    Unsolicited advice

    • This question should be tagged “matlab”. Tag your post with the principal tool or language with which you are having problems so that the right people read it.

    • A short set of steps to reproduce makes it much easier to answer your question. It would have been better to try a few seed values to rng and include the daa function call than the large set of steps with random numbers.

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

Sidebar

Related Questions

I have written this program, which sorts some ints using a functor: #include<iostream> #include<list>
I have just written some code, which as i was writing i thought, this
I had written this code out using Adobe CS3 and have recently upgraded to
I have written this code inside a servlet to delete certain records from three
I have written this code in JavaScript and works perfectly fine when I include
I have written this function to auto correct gender to M or F from
I have written this code what it does is if user types postcode or
I have written this code outside all functions: int l, k; for (l =
have written this little class, which generates a UUID every time an object of
I have written this regexp: <(a*)\b[^>]*>.*?</\1> and is tested on this regexp testing site:

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.