make plot the square wave
Mostrar comentarios más antiguos

[A, B] = square_wave_fun(0.1, 1, 0.0001, -1250, 1250);
plot(B, A, '-k');
--------------------------
For obtaining the picture, how can the above code be changed?
If you couldnt from the above code, recommend the other way.
thanks
5 comentarios
Rik
el 3 de Dic. de 2020
That depends on the contents of square_wave_fun.
function [x, T_s_vct] = square_wave_fun(T, A, T_s, W_b, W_e)
T_s_vct = [W_b : T_s : W_e];
x_T = -1 * ones(1, length(T_s_vct));
for ii = floor(W_b/T) : ceil(W_e/T)
x_T(( -T/4 + ii* T < T_s_vct ) & ( T_s_vct < T/4 + ii* T ) ) = 1;
end
x = x_T;
return
Rik
el 3 de Dic. de 2020
I believe I have told you before that a function without documentation is almost useless.
If this function is called with the parameters you mention in your question, it will take a very long time and produce a very large output. When I reduced T_s to 0.01 and only plotted the first 100 elements of A and B I got a square wave pulse, so it seems like your code works.
Start by writing good documentation and comments for your function. Only then can we start adjusting the inputs to make sure you get the plot you want.
Two last things:
- Do you just want this plot, or are you required to use this function to create the plot?
- Either remove the A input from your function, or use it somewhere. Don't ignore mlint warnings.
Rik
el 3 de Dic. de 2020
Since you're required to use this function, this must be homework. You can find guidelines for posting homework on this forum here. If you have trouble with Matlab basics you may consider doing the Onramp tutorial (which is provided for free by Mathworks). If your main issue is with understanding the underlying concept, you may consider re-reading the material you teacher provided and ask them for further clarification.
Regarding A, you misunderstood what I meant. If you look at the function signature you will see that the second input is not used anywhere in the function. It can therefore be removed from the signature
You're free to use the 0.0001 as the third input, but you should be prepared to wait a very long time for the function to finish.
Rik
el 3 de Dic. de 2020
Why did you edit away part of your question? Are you afraid to be caught cheating? If that is the case: too bad. I hope your teacher googles your name so they can find this. I will restore the question from the Google cache. If you don't want something online you shouldn't publish it.
make plot the square wave

[A, B] = square_wave_fun(0.1, 1, 0.0001, -1250, 1250);
plot(B, A, '-k');
--------------------------
For obtaining the picture, how can the above code be changed?
If you couldnt from the above code, recommend the other way.
thanks
Rik
el 3 de Dic. de 2020
There were also two comments, which are only partially visible in my activity feed:
yes thats right
- require this function to create.
A and B can be changed to below
[x, T_s_vct] = square_wave_fun(0.1, 1, 0.0001, -1250, 1250);
plot(T_s_vct, x, '-k');
Respuestas (1)
Rik
el 3 de Dic. de 2020
Since this is homework, I left some holes for you to fill.
T=___;%what should the period of your square wave pulse be if you want it to go down at 1250?
% This is the entire length of the pulse. It will go down at 1/4 of the period.
[x, T_s_vct] = square_wave_fun(T, 'this can be anything, as it is ignored by your function',...
0.0001, -1500, 1500);
x=____; %adjust x so it is 0 or 1, instead of -1 and 1
figure(1),clf(1)
plot(T_s_vct, x, '-k');
axis([___])%adjust the
function [x, T_s_vct] = square_wave_fun(T, A, T_s, W_b, W_e)
T_s_vct = [W_b : T_s : W_e];
x_T = -1 * ones(1, length(T_s_vct));
for ii = floor(W_b/T) : ceil(W_e/T)
x_T(( -T/4 + ii* T < T_s_vct ) & ( T_s_vct < T/4 + ii* T ) ) = 1;
end
x = x_T;
end
Categorías
Más información sobre Loops and Conditional Statements en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!