Borrar filtros
Borrar filtros

Inputs must be 2-D, or at least one input must be scalar

29 visualizaciones (últimos 30 días)
hamed
hamed el 28 de Jul. de 2016
Editada: Guillaume el 29 de Jul. de 2016
I have the following codes:
[l,r,h3]=size(H);
maxc=max(c);
h=H*ones(h3,1);
z1=(maxc/r)*ones(r,1);
So, when I want to run the function, I get the following error:
Error using *
Inputs must be 2-D, or at least one input must be scalar.
To compute elementwise TIMES, use TIMES (.*) instead.
Error in Trump (line 19)
h=H*ones(h3,1);
Thanks
  3 comentarios
Adam
Adam el 28 de Jul. de 2016
Did you try doing exactly what the error message suggested you do?
hamed
hamed el 28 de Jul. de 2016
Hello
I have totally two kinds of errors:
First, it was something like the one that I have mentioned in the last question and the other one is, "matrix dimension must agree."

Iniciar sesión para comentar.

Respuestas (1)

Guillaume
Guillaume el 28 de Jul. de 2016
Editada: Guillaume el 28 de Jul. de 2016
You have to ensure that the things you multiply are the same size or that one of them is scalar. In H * ones(h3, 1), the right hand side ( ones(h3, 1)) is h3 rows by 1 column (a column vector). Considering the previous line, you would assume that H is 3D. The two are not compatible.
You could solve that by ensuring that the matrix of ones you're creating is the same size as H (so ones(l, r, h3)), or you could use bsxfun which would expand singleton dimensions, but in the end. all you're doing is multiplying by 1, so what's the point of all these multiplications?
  2 comentarios
hamed
hamed el 29 de Jul. de 2016
Thanks a lot for your answer. The aim of these multiplications is to calculate z1.
beta_p=1e-4;
gamma=0.1;
h=H1*ones(h3,1);
z1=(maxc/r)*ones(r,1);
y=H1*z1; p1=1e-3*ones(l,1);
q1=0*ones(l,1); % initial the delay price
q2=q1;
p2=p1;
s=p1+q1;
z2=zeros(r,1);
Maxiter=100;
Utility=[];
AggreThroughput=[];
for k=1:Maxiter
m1=H1'*s;
for i=1:ms
iflowR=sum(z1((i-1)*path+1:i*path));
for j=1:path
Cindex=(i-1)*path+j;
temp=z1(Cindex)-(gamma*(iflowR-1/m1(Cindex)))/h(Cindex);
Guillaume
Guillaume el 29 de Jul. de 2016
Editada: Guillaume el 29 de Jul. de 2016
Please, use the {}Code button to format your code. It's much simpler than adding a blank line between each line of code (just paste the code and click the button) and results in much more readable posts.
Are you aware of what ones does? It creates a matrix of one. Multiplying something by one (no matter how many there are) does not change its value. It's completely pointless
You even have q1 = 0*ones(I, 1), 0 times 1 is zero, so q1 = zeros(I, 1) is going to be identical.
I have no idea what you're doing, but all these *ones(something, 1) are absolutely pointless.
edit: the above assumes you meant to perform element-wise multiplication (using .* instead of *). If you were actually intending matrix multiplication, then the numbers of columns of the first matrix must be equal to the number of rows of the second matrix. Multiplying by a column of 1 is still pointless, the same can be achieved with the much clearer:
result = sum(input, 2)

Iniciar sesión para comentar.

Categorías

Más información sobre Loops and Conditional Statements en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by