trying to make a switch case for the dropdown with options: sine,cosine,square, triangular, to plot the right wave whenever chosen, this only plots sine wave, what's wrong?

17 ビュー (過去 30 日間)
value = app.SignalGeneratorDropDown.Value;
app.t=0:0.01:1
app.A= app.AmplitudeEditField.Value;
app.f= app.FrequencyEditField.Value;
app.y=app.A*sin(2*pi*app.f*app.t);
switch value
case "Sine"
app.y=app.A*sin(2*pi*app.f*app.t);
case "Square"
app.y=app.A*Square(2*pi*app.f*app.t);
case "Cosine"
app.y=app.A*cos(2*pi*app.f*app.t);
case "Triangular"
app.y=app.A*sawtooth(2*pi*app.f*app.t);
end
plot(app.UIAxes,app.t,app.y);
xlabel(app.UIAxes,"Time")
ylabel(app.UIAxes,"Amplitude")
title(app.UIAxes,"waveform")

回答 (1 件)

Srijith Kasaragod
Srijith Kasaragod 2021 年 11 月 25 日
編集済み: Srijith Kasaragod 2021 年 11 月 25 日
Hi Rana,
I have tried to recreate the issue at my end and the code seems to run correctly, with sin, cos, square and sawtooth waveforms getting plotted onto UIAxes according to dropdown input. Please ensure you have the above code inside DropDown 'ValueChangedFcn' function callback. If the issue still persists, upload your file and we shall have a look at it.
Regards.

カテゴリ

Help Center および File ExchangeManage Products についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by