the code shows the error "the size input must be scalar" .

the code shows the error that the size input must be scalar ., not able to figure out the error.
i=1:100;
n=(0:0.1:30);
a_i=unifrnd(30,90); %% uniformly distributed random number between 30 to 90
w_i=2*pi/600+(2*pi/400-2*pi/600).*rand(n,1); %% uniformly distributed random number with values between 2pi/600 to 2pi/400
theta_i=pi/8+(pi/3-pi/8).*rand(n,1); %% uniformly distributed random number between pi/8 to pi/3
x_i(n)=a_i.*sin(w_i.*n+theta_i)+80;

Answers (1)

DGM
DGM on 29 Sep 2021
Edited: DGM on 29 Sep 2021
You're calling rand() with non-integer vector arguments. The arguments to rand() are the array geometry. With this syntax, the inputs need to be scalar positive integers. It's possible to call rand() with a vector input (e.g. rand([2 2])), but that's not what you're trying to do here.
i = 1:100; % idk what this is for
n = 0:0.1:30;
a_i = unifrnd(30,90);
w_i = 2*pi/600+(2*pi/400-2*pi/600).*rand(numel(n),1); % is that what you meant?
theta_i = pi/8+(pi/3-pi/8).*rand(numel(n),1);
x_i = a_i.*sin(w_i.*n+theta_i)+80; % can't use non-integers as indices
Due to the vector orientation, x_i is 301x301. If you intended for the output to be a vector, you'll have to do one of two things:
% it's unclear if the vector orientation is intended here
% otherwise, transpose n or the specify the correct dimensions when calling rand()
% x_i = a_i.*sin(w_i.*n.' + theta_i)+80; % n transposed

2 Comments

i want to generate a set of sinewaves for the values of i=1,2....100 , for the above given eqn x_i(n), for the value of n =[0:0.1:30] where a_i has random distribution from 30 to 90 , w_i has values from 2pi/600 to 2pi/400 (uniformly distributed random no.) and theta value from pi/8 to pi/3 .
Yes, but how is x a function of i? Nothing in this description is a function of i.

Sign in to comment.

Categories

Find more on Random Number Generation in Help Center and File Exchange

Tags

Asked:

on 29 Sep 2021

Commented:

DGM
on 29 Sep 2021

Community Treasure Hunt

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

Start Hunting!