Error: 'Matrix dimensions must agree' even when using a scalar to multiply with Matrix.

Hello, I am actually multiplying the matrix with a scalar, if I however take the user input for the scalar it displays error as :* Error using '*' Inner matrix dimensions must agree.*
Part of my code that uses this is:
scale = ('Enter the scale for noise to be added to the signal, scale = ');
n=linspace(0,2*pi,N);
s=sin(2*pi*n);
v=randn(1,N);
x=s+v*scale;
However if I implicitly mention the scalar in m-file it works perfectly. The following code works:
scale = 0.2;
n=linspace(0,2*pi,N);
s=sin(2*pi*n);
v=randn(1,N);
x=s+v*scale;
I am a noob, so please be gentle. Any help would be appreciated. Thank you!

 Accepted Answer

Based on the code you placed here, it looks like your first line is missing an input function and is instead just creating a string with the text given. It should read:
scale = input('Enter the scale for noise to be added to the signal, scale = ');

2 Comments

I am frankly ROFLing at myself for this. I had never imagined I could be stupid to this level. I think I must get some sleep before continuing with my project. Thank you so much. You're a life saver. :)
Haha, no worries--it happens to everyone. I once did much the same thing in a question here. Except I went one further and swore up and down that it must have been a bug in my version of Matlab. :P

Sign in to comment.

More Answers (0)

Asked:

on 10 Jul 2013

Community Treasure Hunt

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

Start Hunting!