matlab输入变量赋值,在matlab中怎么用输入量给变量赋值?

b42cc57de4748bd8fb968e785f80be6b.png

比如说你要给变量n赋值,你可以这样写:

n=input('请输入n的值:');

当你运行的时候,再主窗口会提示,请输入n的值:

当你输入值后,那个值就赋给了变量n

需要说明的是输入n的格式,你应该知道matlab中的变量都是以矩阵形式存在的吧,所以如果n是一个m*k的矩阵的话,比如1 2 3,应该输入[1 2 3],如果n只是1*1的矩阵(就是一个数),那么直接输入就是了,不需要中括号

你看下面一个利用DFT求线性卷积的例子,也涉及到了输入量赋给变量

% Program 5_4

% Linear Convolution Via the DFT

%

% Read in the two sequences

x = input('Type in the first sequence = ');

h = input('Type in the second sequence = ');

% Determine the length of the result of convolution

L = length(x)+length(h)-1;

% Compute the DFTs by zero-padding

XE = fft(x,L);  HE = fft(h,L);

% Determine the IDFT of the product

y1 = ifft(XE.*HE);

% Plot the sequence generated by DFT-based convolution and

% the error from direct linear convolution

n = 0:L-1;

subplot(2,1,1)

stem(n,y1)

xlabel('Time index n');ylabel('Amplitude');

title('Result of DFT-based linear convolution')

y2 = conv(x,h);

error = y1-y2;

subplot(2,1,2)

stem(n,error)

xlabel('Time index n');ylabel('Amplitude')

title('Error sequence')

0

◆◆

评论读取中....

请登录后再发表评论!

◆◆

修改失败,请稍后尝试

  • 3
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值