error:Deminsion 2 is fixed on left hand side but varies on right([1x1]}~=([1x:?])

1 vue (au cours des 30 derniers jours)
While convertio=ng my code fro matlab to c++ I am showing some error; which says Deminsion 2 is fixed on left hand side but varies on right([1x1]}~=([1x:?])
this is my code which i was trying to convert where T is 1x401 and Y is 1x21
function summ = u_sum(T,Y)
summ = 0;
for i=1:20
lmd = (2*i+1)*pi;
a = 4/((lmd)^3);
b = sin(lmd*Y);
c = exp(-(lmd^2)*T);
summ = summ + (a*b*c);
end
end

Réponse acceptée

Mathieu NOE
Mathieu NOE le 10 Nov 2020
hi
there is something wrong in your code
a, b,c have different dimensions so the product a*b*c is not possible (summ = summ + (a*b*c); )
Name Size Bytes Class
T 1x401 3208 double array
Y 1x21 168 double array
a 1x1 8 double array
b 1x21 168 double array
c 1x401 3208 double array
i 1x1 8 double array
lmd 1x1 8 double array
summ 1x1 8 double array
  3 commentaires
Mathieu NOE
Mathieu NOE le 10 Nov 2020
as mentionned above by Walter , you have to decide how to index Y and T in the a,b,c terms , (if they must all be scalars)
I cannot guess that for you , because I don't know what your summ computation is supposed to do
Sameeksha Singh
Sameeksha Singh le 13 Nov 2020
@Mathieu NOE thankyou so muchh

Connectez-vous pour commenter.

Plus de réponses (1)

Walter Roberson
Walter Roberson le 10 Nov 2020
summ = 0;
That is a scalar. Once that assignment is made, the variable cannot grow larger..
b = sin(lmd*Y);
That uses all of Y, so b would be 1x21.
summ = summ + (a*b*c);
scalar plus scalar times vector times scalar gives vector right hand side. But you try to assign to summ which has been created as a scalar. When you are doing code generation, variables cannot grow unless you use special forms.
If you want a vector output then initialize summ to zeroes(size(Y)).
I suspect that you might have wanted to index Y in the loop

Catégories

En savoir plus sur Matrix Indexing dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by