MATLAB Answers

how to multiply each row in a column by different numbers

Asked by Passband Modulation on 5 Oct 2012

say, a file consists of a single column with 10000 rows

 load file.txt
 a = file;                       
 s = a(k,1).*cosd(3.6*k); 

it does work at all, could anyone help?


Image Analyst
on 5 Oct 2012

Do you know how to use the debugger to step though your code? This would be easily solved if you did that.

it says:

Error in ==> Untitled3 at 5 s = a(k,1)-56.97*cosd(3.6*k)-31.98*sind(3.6*k);

how to fix it, i really have no any idea.


No products are associated with this question.

1 Answer

Answer by John
on 5 Oct 2012
 Accepted answer

Try this if a is a column vector:

load file.txt

a = file;

k = [1:size(a,1)]';

s = a.*(cosd(3.6*k));



Alternatively, k can be any column vector you wish to perform element-by-element multiplication with a. Just make sure a and k are of the same size.

  1 Comment

a and k are of the same size.

and thank you for your kind reply!!

Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi test

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

MATLAB Academy

New to MATLAB?

Learn MATLAB today!