Getting error matrix dimensions must agree when I run a stack that calculates the sin of the last number on the stack.
7 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
i have a rpmcalcuator stack that only takes certain operands. sin is one of them. when i try to add sin to my stack, it gives me an error.
i am attaching both files. stackmain runs rpm calc. if you could help me figure out how to code my sin function i would appreciate it.
0 commentaires
Réponse acceptée
Geoff Hayes
le 26 Sep 2014
Modifié(e) : Geoff Hayes
le 26 Sep 2014
Nicole - a helpful statement to run before executing your code is dbstop if error. This will cause the code to pause at the line that is generating the error message. In your case, the error occurs at
elseif (x == 'pi')
because you are comparing a string of length three (for sin) versus a string of length two (for pi).
elseif strcmpi(x,'pi')
Do the same for the comparison with 'e' and try running through the code again.
EDIT
Once you fix the above, you will notice an error at line 94 of RPMCalculator
self.push(num2str(sin(self.data(self.top-1),u)));
because the variable u is undefined. Since sin only takes one input, you can remove this.
6 commentaires
Geoff Hayes
le 28 Sep 2014
Hi Nicole - I think it is because of the disp(x) in the math function that the + or sin or - is appearing. You shouldn't need to put semi-colons after the case argument. As soon as I commented out the disp(x) line, the only output in the Command Window (when running your original StackMain is
d (i) =
12
The last 3 values on the stack are:
4
3
12
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Entering Commands 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!