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 using ==> times

Subject: ??? Error using ==> times

From: Jim

Date: 8 Sep, 2010 12:59:04

Message: 1 of 4

Can you help me with my code?
When I compile I get the error:
??? Error using ==> times
Matrix dimensions must agree.
I'm new and I don't get it...
My code is about power control via pricing:
My code is:
close all; %gia na kleisei oles tis proigoumenes eikones
clear all; %gia na katharisei ti mnimi

%orismos dedomenwn
L=64;
R=10^4;
M=80;
W=10^6;
s2=5*10^(-15);
pmax=2;
k=0.097*10^(-3);
pj=0.01:0.001:pmax;
d=[0.31 0.46 0.57 0.66 0.74 0.81 0.88 0.94 1.00];
h=k./(d.^4);
ind=1;
ind2=1;
p(ind,ind2,:)=ones(1,1,9);
q=zeros(1,1,9);
for c=1:10^3:10^5;
    
while max(abs(p(ind,ind2,:)-q))>10^(-4)
    q=p(ind,ind2,:);
    ind=ind+1;
    
    for i=1:9
       
        g=(W/R)*(h(i)*pj)/(sum(h(1:(i-1)).*p(ind-1,ind2,1:(i-1)))+sum(h((i+1):end).*p(ind-1,ind2,(i+1):end)) + s2);
        pe=0.5.*exp(-g./2);
        f=(1-2.*pe).^M;
        u=L*R.*f./(M.*pj)-c.*pj;
        um=max(u);
        kk=find(u==um);
        p(ind,ind2,i)=pj(kk);
  
    end
    
   
       
end
ind2=ind2+1;
end

Subject: ??? Error using ==> times

From: Oleg Komarov

Date: 8 Sep, 2010 13:05:05

Message: 2 of 4

"Jim " <jmo2005@gmail.com> wrote in message <i681ao$qeu$1@fred.mathworks.com>...
> Can you help me with my code?
> When I compile I get the error:
> ??? Error using ==> times
> Matrix dimensions must agree.

g=(W/R)*(h(i)*pj)/(sum(h(1:(i-1)).*p(ind-1,ind2,1:(i-1)))+sum(h((i+1):end).*p(ind-1,ind2,(i+1):end)) + s2);

The error lies here. Run shorter parts of the expression to locate were the problem is.

Oleg

Subject: ??? Error using ==> times

From: Jim

Date: 8 Sep, 2010 14:24:04

Message: 3 of 4

"Oleg Komarov" <oleg.komarovRemove.this@hotmail.it> wrote in message <i681m1$k4g$1@fred.mathworks.com>...
> "Jim " <jmo2005@gmail.com> wrote in message <i681ao$qeu$1@fred.mathworks.com>...
> > Can you help me with my code?
> > When I compile I get the error:
> > ??? Error using ==> times
> > Matrix dimensions must agree.
>
> g=(W/R)*(h(i)*pj)/(sum(h(1:(i-1)).*p(ind-1,ind2,1:(i-1)))+sum(h((i+1):end).*p(ind-1,ind2,(i+1):end)) + s2);
>
> The error lies here. Run shorter parts of the expression to locate were the problem is.
>
> Oleg
I did.
Here are the results:
h(1:(i-1))

ans =

   Empty matrix: 1-by-0

>> p(ind-1,ind2,1:(i-1))

ans =

   Empty array: 1-by-1-by-0
sum(h((i+1):end))

ans =

    0.0045
p(ind-1,ind2,(i+1):end)

ans(:,:,1) =

     1


ans(:,:,2) =

     1


ans(:,:,3) =

     1


ans(:,:,4) =

     1


ans(:,:,5) =

     1


ans(:,:,6) =

     1


ans(:,:,7) =

     1


ans(:,:,8) =

     1

>>

I think it might be something deeper than this.Something fundamental that I don't get...

Subject: ??? Error using ==> times

From: Sean

Date: 8 Sep, 2010 14:34:08

Message: 4 of 4

"Jim " <jmo2005@gmail.com> wrote in message
> Here are the results:
> h(1:(i-1))
>
> ans =
>
> Empty matrix: 1-by-0
>
> >> p(ind-1,ind2,1:(i-1))
>
> ans =
>
> Empty array: 1-by-1-by-0

What happens if you fill in:
squeeze(p(ind-1,ind2,1:(i-1)))
?

The first empty array that you had was 2-dimensional (Empty matrix: 1-by-0) and the second 3-dimensional (Empty array: 1-by-1-by-0); of course they won't be the same size. Squeezing removes the third dimension. Just a thought...
-Sean

Tags for 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