Asked by Bob
on 15 Nov 2012

I'm trying to creat a multiplication table for the following

f=[5:.332:55]; omegahz=(2*pi)*f; amp=0:0.01:1.5;

My attempt was

f=[5:.332:55]; omegahz=(2*pi)*f; amp=0:0.01:1.5;

for n=1:151 omegan =omegahz(1,n) ampn= amp(1,n)

g(ampn,omegan)=ampn*omegan

end

so I think I have to call on the location not the value so I tried this

f=[5:.332:55]; omegahz=(2*pi)*f; amp=0:0.01:1.5;

for n=1:151 omegan =omegahz ampn= amp

g(ampn,omegan)=ampn.*omegan end

and get this

??? Subscript indices must either be real positive integers or logicals.

Error in ==> Untitled3 at 10

g(ampn,omegan)=ampn.*omegan

I'm Not sure how to proceed on this one, Your help Is appreciated. Thanks

Answer by Loginatorist
on 15 Nov 2012

Edited by Loginatorist
on 15 Nov 2012

Accepted Answer

I am not quite sure if this is what you want, but have a look at this:

A = 1:5;, B = 1:10; C = bsxfun(@times,A,B.') % Also try bsxfun(@times,A.',B)

The error you got is easy to understand. You cannot index into an array with anything but a nonpositive integer or logical. Think about it. Consider this array:

A = [10 11 12];

What is the first element? A(1) is 10. What is the second element? A(2) is 11. What about the third element? A(3) is 12. So what element is A(2.23)? *NONE.*

Bob
on 17 Nov 2012

thanks, so I'm testing using the first 5 values to see if I get my table, when I try it with the values of k,n to creat (test) I get the correct table but when I use my w2,a to creat (ac)table I get the columns of the same value

a=[0:.001:.015]; w=[10*pi:6.13:100*pi]; w2=w.^2; amax=.18*9.81; %a=a'; for k=1:5 ; for n=1:5 ; test(k,n)=k*n y=w2(1,n); x=a(1,n); ac(k,n) = bsxfun(@times,x,y.') ; end end end end

Loginatorist
on 17 Nov 2012

Bob, did you look at the output of my code? Why are you trying to use BSXFUN on two scalar values? x and y are both scalars, but BSXFUN is for vectors.

If 'test' is the array you want, and you already can get it, what is your question about? Are you looking for this:

ac = bsxfun(@times,a(1:n),w2(1:n).'); % Not in a loop!

You need to explain what you want at the end, given those inputs.

Bob
on 17 Nov 2012

I was confused on where I was going with it. now im still confused but I know where I'm going with it. Initially I though bsxfun was't what I needed and thought 2 for loops might give me what I need.

I have a machine with 2 inputs:

1. amplitude Range(0,0.015)

2.Freq Range(5,55)

Equation:

w=Freq*2*Pi

Acceleration=Amp*W^2

that's why i wanted the Table for

After I get my table I need to extract the (AMP,W)Pairs that generates acceleration =1.76

I Created the table using Excel and compared it my results from mat lab, I found that my interval for w and w^2 are not of equal size, and thats why my results don't match.

this is the excel sheet I'm using :

https://docs.google.com/open?id=0B6m94M0Cqc9Ad3B3RmdNamZEQ1E

here is my latest code, still trying to get

a=[0:.001:.015]; w=[10*pi:6.2:100*pi]; w2=w.^2; amax=.18*9.81;

C = bsxfun(@times,w2,a.') % Also try bsxfun(@times,A.',B)

Thanks

Log in to comment.

Related Content

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

Learn moreOpportunities for recent engineering grads.

Apply Today
## 0 Comments

Log in to comment.