フィルターのクリア

How can i plot a sine wave using parameters input by user?

4 ビュー (過去 30 日間)
Estee-Naomie Kadima
Estee-Naomie Kadima 2020 年 8 月 27 日
コメント済み: Star Strider 2020 年 8 月 27 日
clc;
close all;
clear all;
t=0:0.01:10
a= inputdlg
f=0.5;
y= a*sin(2*pi*f*t)
subplot(2,1,1)
plot(t,y);
axis([-10 10 -10 10]);
title('Sine Function');
xlabel('Time axis');
ylabel('Amplitude axis')
When i put a number as 'a' and run the script it produces a sine graph. However i want the script to work when 'a' can be inputted by the user. When i use 'inputdlg' it prompts for me to place a figure however when i do the following shows up in the command line.
Error in Attuntitled2 (line 8)
y= a*sin(2*pi*f*t)

採用された回答

Star Strider
Star Strider 2020 年 8 月 27 日
I prefer inputdlg, however you need to remembert that the output is a cell array or character vectors.
To enter an amplitude value of 42:
ac = inputdlg('Enter a value for the amplitude ')
a = str2double(ac)
produces:
ac =
1×1 cell array
{'42'}
a =
42
Put semiccolons at the end of the statements to prevent them printing to your Command Window. I did not use them here for demonstration purposes.
  2 件のコメント
Estee-Naomie Kadima
Estee-Naomie Kadima 2020 年 8 月 27 日
Thank you very much!! It worked
Star Strider
Star Strider 2020 年 8 月 27 日
As always, my pleasure!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeSignal Analysis についてさらに検索

製品


リリース

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by