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 "Subscripted assignment dimension mismatch"

Subject: Error Message "Subscripted assignment dimension mismatch"

From: Guan Hong

Date: 23 Mar, 2012 06:26:22

Message: 1 of 3

Hi, I have encountered an error message "Subscripted assignment dimension mismatch" while running the m-file below. I would like to seek your expertise as I am new to MatLab. Your help will be greatly appreciated.

%---------Pairwise Comparison: Eigenvector Method-------------
disp('----Pairwise Comparison: Eigenvector Method----')
PM =[1/1 4/1 8/7 8/3 8/7 1/1 8/5 8/1 4/3 4/3;
    1/4 1/1 2/7 2/3 2/7 1/4 2/5 2/1 1/3 1/3;
    7/8 7/2 1/1 7/3 1/1 7/8 7/5 7/1 7/6 7/6;
    3/8 3/2 3/7 1/1 3/7 3/8 3/5 3/1 1/2 1/2;
    7/8 7/2 1/1 7/3 1/1 7/8 7/5 7/1 7/6 7/6;
    1/1 4/1 8/7 8/3 8/7 1/1 8/5 8/1 4/3 4/3;
    5/8 5/2 5/7 5/3 5/7 5/8 1/1 5/1 5/6 5/6;
    1/8 1/2 1/7 1/3 1/7 1/8 1/5 1/1 1/6 1/6;
    3/4 3/1 6/7 2/1 6/7 3/4 6/5 6/1 1/1 1/1;
    3/4 3/1 6/7 2/1 6/7 3/4 6/5 6/1 1/1 1/1]
Wt(:,1)=[1;0;0;0;0;0;0;0;0;0]
[len,width]=size(PM); %3 x 3 matrix
delta(:,1)=[1 1 1 1 1 1 1 1 1 1]';
trial=100;


for t=2:trial
    Wt1(:,t)=PM*Wt(:,t-1);
    max_eig=sum(Wt1(:,t));
    Wtnorm1(:,t)=Wt1(:,t)./max_eig;
    delta(:,t-1)=abs(Wt(:,t-1)-Wtnorm1(:,t));
    if delta(:,t-1)>=1e-6
        Wt(:,t)=Wtnorm1(:,t);
    else
        CI=(max_eig-width)/(width-1);
        weight=Wtnorm1;
        break
    end
end
final_weight=weight(:,length(weight))
disp(['After ', num2str(t),' iterations.........'])
disp(['The pairwise comparison result is [',num2str(final_weight(1)),' ', num2str(final_weight(2)),' ', num2str(final_weight(3)),' ', num2str(final_weight(4)),' ', num2str(final_weight(5)),' ', num2str(final_weight(6)),' ', num2str(final_weight(7)),' ', num2str(final_weight(8)),' ', num2str(final_weight(9)),' ', num2str(final_weight(10)),']' ])

Subject: Error Message "Subscripted assignment dimension mismatch"

From: Roger Stafford

Date: 23 Mar, 2012 18:48:18

Message: 2 of 3

"Guan Hong " <jail_mage86@hotmail.com> wrote in message <jkh52e$ko5$1@newscl01ah.mathworks.com>...
> Hi, I have encountered an error message "Subscripted assignment dimension mismatch" while running the m-file below. I would like to seek your expertise as I am new to MatLab. Your help will be greatly appreciated.
> ......
> if delta(:,t-1)>=1e-6
>......
> final_weight=weight(:,length(weight))
> ......
- - - - - - - - - -
  One cause of trouble would likely be with the line:

 final_weight=weight(:,length(weight))

If you arrive there with the number of columns in 'weight' less than 10, the quantity "length(weight)" will nevertheless be equal to 10 and that will produce an error message. You shouldn't use 'length' there, use 'size(weight,2)' (or better still use 'end'.).

  That may not be your only difficulty, though. In the 'if' statement you have:

 delta(:,t-1)>=1e-6

My guess is that you want this to be considered true if any of the elements in delta(:,t-1) are greater than or equal to 1e-6. However matlab will only regard it as true if all of them are greater than or equal to 1e-6. That could cause you to do a 'break' prematurely. You need to use the 'any' function in that case.

Roger Stafford

Subject: Error Message "Subscripted assignment dimension mismatch"

From: Guan Hong

Date: 26 Mar, 2012 08:44:12

Message: 3 of 3

"Roger Stafford" wrote in message <jkighi$e6a$1@newscl01ah.mathworks.com>...
> "Guan Hong " <jail_mage86@hotmail.com> wrote in message <jkh52e$ko5$1@newscl01ah.mathworks.com>...
> > Hi, I have encountered an error message "Subscripted assignment dimension mismatch" while running the m-file below. I would like to seek your expertise as I am new to MatLab. Your help will be greatly appreciated.
> > ......
> > if delta(:,t-1)>=1e-6
> >......
> > final_weight=weight(:,length(weight))
> > ......
> - - - - - - - - - -
> One cause of trouble would likely be with the line:
>
> final_weight=weight(:,length(weight))
>
> If you arrive there with the number of columns in 'weight' less than 10, the quantity "length(weight)" will nevertheless be equal to 10 and that will produce an error message. You shouldn't use 'length' there, use 'size(weight,2)' (or better still use 'end'.).
>
> That may not be your only difficulty, though. In the 'if' statement you have:
>
> delta(:,t-1)>=1e-6
>
> My guess is that you want this to be considered true if any of the elements in delta(:,t-1) are greater than or equal to 1e-6. However matlab will only regard it as true if all of them are greater than or equal to 1e-6. That could cause you to do a 'break' prematurely. You need to use the 'any' function in that case.
>
> Roger Stafford

Thank you Roger Stafford for the advice. I've solved the error. Really appreciate your help. =)

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