gpt4 book ai didi

matlab - 在 MATLAB 中,单引号和双引号有什么区别?

转载 作者:行者123 更新时间:2023-12-01 22:05:14 25 4
gpt4 key购买 nike

例如,如果我想从用户那里得到一个整数,并使用输入函数:

prompt = "please input the sigma value for Gaussian filtering"
sigma = input(prompt)

会给出错误信息

同时

prompt = 'Please input the sigma value for Gaussian filtering'
sigma = input(prompt)

将成功运行并获取用户输入。

我的问题是,""和 '' 有什么区别?

谢谢。

最佳答案

虽然字符数组和字符串在很多方面可以互换,但还是有一些区别。

这是我最喜欢的学生示例:

>> a = ['1','2']

对比

>> b = ["1","2"]

生成的 a 是字符数组 '12'b 是一个包含条目的 1x2 字符串数组“1”“2”

第二个,希望更有启发性的例子是

>> d = sprintf("%1.2e1",3.4)
>> e = sprintf('%1.2e1',3.4)
>> d(1)
>> e(1)

请注意如何在 sprintf 等字符串操作函数中使用这两种样式,但是生成的数组对于 d1x1 ,对于 1xn e

关于matlab - 在 MATLAB 中,单引号和双引号有什么区别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52347114/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com