d2jsp
Log InRegister
d2jsp Forums > Off-Topic > Computers & IT > Programming & Development > Matlab Error > Help Please
Add Reply New Topic New Poll
Member
Posts: 4,635
Joined: May 3 2009
Gold: 1,232.52
Jan 24 2018 05:28pm
Don't understand what this error is saying. I just want to evaluate the equation for each value of fD and store the value in the array "b".

The code
Code
B = 200e3; %3dB Bandwidth (200 kHz)
T = 500e-6; %Pulsewidth (100 us)
t = 0:1e-7:T; %Plotting variable
LFMwaveform = @(x) (1/sqrt(T))*exp(i*((pi()*B*(x.^2))/T));
b = zeros(5001,0)
for fD = 1:5001
b(fD) = LFMwaveform(t).*exp(j*2*pi().*fD);
end


The error
Code
In an assignment A(:) = B, the number of elements in A and B must be the same.

Error in WorkAssignment1_V2 (line 33)
b(fD) = LFMwaveform(t).*exp(j*2*pi().*fD);


I made the size of "b" 5001 because that's the size of LFMwaveform, but it didn't fix the issue.

Any ideas?
Member
Posts: 108
Joined: Jan 24 2009
Gold: 373.85
Jan 24 2018 10:08pm
On line 33 you were assigning a matrix LFMwaveform(t).*exp(j*2*pi().*fD) to an element b(fD)

Code
B = 200e3; %3dB Bandwidth (200 kHz)
T = 500e-6; %Pulsewidth (100 us)
t = 0:1e-7:T; %Plotting variable
LFMwaveform = @(x) (1/sqrt(T))*exp(i*((pi()*B*(x.^2))/T));
fD = 1:5001;
b = LFMwaveform(t).*exp(j*2*pi().*fD);
Member
Posts: 4,635
Joined: May 3 2009
Gold: 1,232.52
Jan 25 2018 01:28pm
Wait so I don't even need a for loop?

I'm trying to create a column array "b" of 5001 values, and then afterwards I want to convolve b with another function of the same length.

Then I'm going to plot it with the imagesc() command.
Member
Posts: 108
Joined: Jan 24 2009
Gold: 373.85
Jan 25 2018 07:21pm
You're working with matrices/column arrays so you don't need a for loop.

In your for loop you were trying to assign the values of a function evaluated at t to elements of the array b. You can do that in one operation in MATLAB. If you wanted to use a for loop the body would look like

Code
b(fD) = LFMwaveform(t(fD)).*exp(j*2*pi().*fD);

Note the subscript to t. Also, I think b = zeros(5001,0) needs to be b = zeros(5001,1) (at least for it to work in Octave).
Go Back To Programming & Development Topic List
Add Reply New Topic New Poll