Sampling with vectors at the same time
5 views (last 30 days)
its a simple question, but i havent managed to solve it:
I have to sample a vector and the matlab doesn't understandme and prompts:
??? Error using ==> mtimes
Inner matrix dimensions must agree.
I wanted to sample a SUM (cos(2*pi*d*A) )where A is a vector of many degrees value, so I have:
A = [1,2,3,....]
SUM (cos(2*pi*d*A) )
and the input is:
How can I make understand first vector is a sampling and second is a vector of values? (The idea is plotting (sample,d) )
The fact is that the expresion of the vector is a real for each value of d so I should expect something returning results of the SUM of different d's like:
Columns 1 through 11
1 2 3 4 5 6 7 8 9 10 11
Columns 12 through 20
12 13 14 15 16 17 18 19 20
But it doesn't understand each
Dr. Seis on 25 Feb 2013
Edited: Dr. Seis on 25 Feb 2013
d = 1:20;
A = [24,34,56,66,86];
Obviously, in this simple case, the answer will always be 5 for all d since we are dealing with integer multiples of 2*pi (and there are only 5 elements in A), but I think this is what you are looking for.
More Answers (4)
Image Analyst on 24 Feb 2013
Edited: Image Analyst on 24 Feb 2013
What is SUM? Is it a custom function you wrote, or an array of yours, because it's not the built-in MATLAB sum() function because MATLAB is case sensitive.
Perhaps you meant something like this:
A = 1:20
cosA = cos(2*pi*d.*A)
theSum = sum(cosA)
Note the .* instead of * between d and A to do an element by element multiplication, not a matrix multiplication like you were trying to do.