【发布时间】:2015-04-27 10:10:03
【问题描述】:
首先,我的编程能力不是很好,所以请多多包涵。
我正在尝试在 Matlab,R2015a 中编写以下脚本:
1) 给定某个向量 (mag),从该向量的前 300 个值(Am 和 A)中计算出两个显着值;
2) 获取Am的值的索引,以及A值的两个索引(向量是对称的,所以A会有两个索引);
3) 从另一个向量(@ 987654333@).
4) 最后,根据3)中的值计算D。
到目前为止,这就是我所拥有的:
Am=max(mag(1:300)); %Am is the maximum value of vector mag
A=Am/2^0.5; %A is the other desired value
[~,Im] = mag(1:300,Am); %Trying to get the Am index. Error: "Indexing cannot yield multiple results." I found that this error is usual when using variables with the same name, which is not the case.
fm=freq(Im); %Value of freq associated with Am
[~,I1] = mag(1:300,A,'first'); %Index of the first value of A
f1=freq(I1) ; %Value of freq associated with the first value of A
[~,I2] = mag(1:300,A,'second'); %Index of the second value of A
f2=freq(I1); %Value of freq associated with the second value of A
D=(f2^2-f1^2)/(4*fm)
我无法从mag 的欲望值中获取关联的freq 值。欢迎提供任何提示和建议。
提前谢谢你!
【问题讨论】:
-
发现我可以用 [~,I1] = max(mag(1:300)) 替换 [~,Im] = mag(1:300,Am) 效果很好。其他两个索引的问题仍然存在。
-
在您的第一段代码中,您使用
mag作为变量,进一步作为函数。这里没有任何意义。 -
@thewaywewalk,如果您想从 A 的两个值中获取索引,请忽略其中的内容。我似乎找不到办法,这是一次糟糕的尝试,我的错。