Code Segment works in Command Window but not in script

5 views (last 30 days)
Error Message: "Incorrect dimensions for matrix multiplication."
Variables: X(5000 x 400) and theta (10 X 400);
Code: prob = X * theta';
This code works in the command window but when I try to run this segment of code in a script it gives me the shorten-error message above. Any suggestions on how to make the code run in the script?
  2 Comments
Walter Roberson
Walter Roberson on 17 Jan 2021
dbstop if error
Then run your code. When it stops at that line,
size(X), size(theta)
Vista Marston
Vista Marston on 17 Jan 2021
Thanks! I accidentally re-assigned the variable within my script code. Thanks for all of your guys' help!

Sign in to comment.

Accepted Answer

Cris LaPierre
Cris LaPierre on 17 Jan 2021
Appears to work just fine. Do you define X or theta somewhere in your script with different dimensions? Perhaps clear your workspace?
X=rand(5000,400);
theta = rand(10,400);
prob = X*theta'
prob = 5000×10
105.7642 102.0516 106.3440 99.0930 99.7603 100.6787 110.1098 108.2070 104.9535 103.9118 97.0571 98.3039 100.5952 97.3498 94.9953 99.1180 102.4490 105.2673 101.3217 101.2874 104.4095 99.5615 104.0622 98.7885 97.3690 100.9625 102.1218 104.9444 102.7308 106.6204 98.8063 101.0833 103.2165 94.6448 96.6372 96.6420 103.5771 103.6294 97.6779 99.2154 103.4647 101.6530 99.6302 97.2015 96.0041 100.4448 103.8220 102.5755 99.8264 101.2962 97.7142 96.2292 100.6145 93.3019 92.4816 94.6029 96.8742 101.7118 94.0574 96.8963 96.1861 95.5434 94.9799 94.7473 92.0459 92.0141 100.3539 103.3307 91.9234 95.9397 100.7110 98.0222 101.5445 97.4117 94.5231 97.7009 104.0763 106.0206 99.4743 103.9467 96.8541 94.3715 98.3633 93.2347 91.4022 98.6017 96.1933 101.8328 95.1515 96.7192 103.9315 100.2307 102.6226 99.7083 97.3954 97.8230 103.8981 105.5340 99.4407 102.4084

More Answers (0)

Categories

Find more on Debugging and Analysis in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!