例如,在循环中:
for i=1:10,
% do something...
end
Run Code Online (Sandbox Code Playgroud)
作为矩阵的索引:
mat( i, j ) = 4;
Run Code Online (Sandbox Code Playgroud)
为什么不应该他们作为在Matlab的变量名?
这个问题经常以某种形式出现(例如,见此处或此处).所以我认为我会以一般形式呈现它,并提供一个可能供将来参考的答案.
给定任意数量
n的可能不同大小的向量,生成一个n列矩阵,其行描述从这些向量中获取的元素的所有组合(笛卡尔积).
例如,
vectors = { [1 2], [3 6 9], [10 20] }
Run Code Online (Sandbox Code Playgroud)
应该给
combs = [ 1 3 10
1 3 20
1 6 10
1 6 20
1 9 10
1 9 20
2 3 10
2 3 20
2 6 10
2 6 20
2 9 10
2 9 20 ]
Run Code Online (Sandbox Code Playgroud) 试图理解MATLAB语法:我明白了
(0:3)
Run Code Online (Sandbox Code Playgroud)
是一个行向量,'(forward-quote)运算符是transpose,所以
(0:3)'
Run Code Online (Sandbox Code Playgroud)
是一个列向量.我也在.'一些文件中看到,这些也产生了列向量,所以
(0:3).'
Run Code Online (Sandbox Code Playgroud)
产生与...相同的结果(0:3).
'和之间有什么区别.'?我没有在MATLAB文档中找到任何帮助我理解这一点的内容.
(注意,这个问题是关于语法,主要是,不是之间的区别transpose和ctranspose,因为如果你不知道这'是一个.'是其他的,比回答的问题transpose相对ctranspose是没有帮助回答的问题.与'.在许多MATLAB示例和教程中,'被transpose明确地和不准确地呈现为,并且这一事实导致了用户第一次遇到的问题.'.)
我试图在matlab中绘制L1范数的水平集.但它根本不起作用,我被卡住了.有帮助吗?
x = linspace(-1,1,10);
y = linspace(-1,1,10);
[xm,ym] = meshgrid(x,y);
z = sum(abs(xm-ym));
surfc(x,y,z)
Run Code Online (Sandbox Code Playgroud) function [output1, output2] = fft2D(input)
output1 = input';
output1 = fft(output1);
output1 = output1';
output1 = fft(output1);
output2 = fft2(input);
end
Run Code Online (Sandbox Code Playgroud)
所以我在output2中计算2D FFT input和在输出1中的相同2D FFT input.fft()对于2D矩阵,跨越列向量应用FFT.所以上面我将它应用于行,然后应用于列.
但是对于随机矩阵
[1 1 4 1;
12 13 124 1;
12 2 2 1;
1 1 1 0]
Run Code Online (Sandbox Code Playgroud)
我output1是:
1.0e+02 *
1.7700 + 0.0000i -1.0500 + 0.1400i 1.3700 + 0.0000i -1.0500 - 0.1400i
-0.1000 - 1.4700i -0.0200 + 1.1100i -0.0800 - 1.2100i -0.2400 + 1.1300i
-1.2900 + 0.0000i 1.1900 …Run Code Online (Sandbox Code Playgroud) 我有两个时域信号(X和Y).我试图计算它们之间的传递函数.我使用函数tfestimate,它返回作为频率函数的传递函数和tfestimate估计传递函数的频率向量.它只返回正频率,因为我的信号并不复杂.我的问题是如何在时域中可视化这个传递函数.我尝试了以下代码,但返回的函数在时域中被反转.我想知道为什么.
x = randn(16384,1); % generate random signal
gaussFilter = gausswin(100);
gaussFilter = gaussFilter / sum(gaussFilter); % Normalize.
y = conv(x,gaussFilter);
y = y(1:length(x)); % truancate the Y to be the same length as X
txy = tfestimate(x,y,1024);
tyx = conj(txy(end:-1:2)); % since tfestimate only returns for positive frequency, I estimate the result for negative frequency as the conjugate of positive frequency.
t = ifft([txy' tyx']); % use inverse fourier to visualize transfer function in time domain.
Run Code Online (Sandbox Code Playgroud)
结果't'不是传递函数,而是一个时间相反的版本.有人可以帮我理解发生了什么吗?谢谢.
在MATLAB中,我有一个长度为n的向量x,其中n通常是O(10),我想构建一个大小为[n ^ m,m]的高矩阵A,其中m再次为0(10).矩阵具有一种特殊的形式:如果n = 4且m = 6,则让
x=[x1; x2; x3; x4]
Run Code Online (Sandbox Code Playgroud)
那么A是
x1 x1 x1 x1 x1 x1
x2 x1 x1 x1 x1 x1
x3 x1 x1 x1 x1 x1
x4 x1 x1 x1 x1 x1
x1 x2 x1 x1 x1 x1
x2 x2 x1 x1 x1 x1
x3 x2 x1 x1 x1 x1
x4 x2 x1 x1 x1 x1
x1 x3 x2 x1 x1 x1
. .
. .
. .
x4 x4 x4 x4 x4 x4
Run Code Online (Sandbox Code Playgroud)
实际上,每列都是通过重复x的元素获得的,每列的步幅越来越大.我怎样才能做到这一点?如果可能的话,我更喜欢有效的(矢量化)解决方案,因为正如您所看到的,A的行数随m呈指数增长.非常感谢,
塞尔吉奥 …
我在matlab中创建这个矩阵时遇到了麻烦,基本上我需要创建一个矩阵,其中-1穿过中心对角线,然后是对角线外面的4s(下面的例子).所有其他值都可以为零.
A5 = [-1 4 0 0 0;
4 -1 4 0 0;
0 4 -1 4 0;
0 0 4 -1 4;
0 0 0 4 -1];
Run Code Online (Sandbox Code Playgroud)
我尝试过使用命令,v = [4]; D = diag(v)
但只适用于中心对角线.