I'm scripting & getting a error "Error using * Inner matrix dimensions must agree." Please help me debug this.

qd=[0:0.1:1];
qf=[0:0.1:1];
micro=0.8;
pa=0.5;pd=0.5;Ptd=1;Esd=0.05;
Esa=0.05; Ptsa=0.3;beta=0.2;
temp1 = micro.*(1 - micro.*pa*qd);
temp2 = pd*(Ptd - Esd);
temp3 = pa*(qf*(Ptd - Ptsa - Esa));
temp4 = qd*(-Ptsa -Esa);
temp5 = micro.^2*pa*qd;
temp6 = pd*(Ptd - Esa);
temp7 = pa*(qf*(Ptd - Ptsa -Esa));
temp8 = pa*(qd*(-Ptsa - Esa));
*Usx = temp1*[temp2 + temp3 + temp4] + temp5*[temp6 + temp7 + temp8];*
plot(qd/qf, Usx,'-b');
xlabel('Dropping/Forwarding Propability')
ylabel('Utility of Attacker/Source Victim Uax/Usx')
title('Utility function as a function of Forwardding/Dropping propability of Packets')
The Error Message in Command Window is Error using * Inner matrix dimensions must agree.
Error in sample1 (line 14) * Usx = temp1[temp2 + temp3 + temp4] + temp5*[temp6 + temp7 + temp8];**

2 个评论

when posting code, it'll be much more readable if, in the editor, you highlight the code and click the "{ } code" button located just above the text area.
I have done as suggested.Please I need help on this code in debugging. Can anyone make this code run without any errors

回答(1 个)

Probably you used the mtimes * operator when you actually should have used the times .* operator:
Usx = temp1.*[temp2 + temp3 + temp4] + temp5.*[temp6 + temp7 + temp8];
That works without error. But you are the only one who can check if you algorithm is correct. To avoid making the same mistake again read and understand the difference between matrix and array operations:

此问题已关闭。

关闭:

2021-8-20

Community Treasure Hunt

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

Start Hunting!

Translated by