将数组分配给函数中的矩阵,语法问题(Assigning arrays to a matrix in a function, syntax problems)

编程入门 行业动态 更新时间:2024-10-27 12:25:45
将数组分配给函数中的矩阵,语法问题(Assigning arrays to a matrix in a function, syntax problems)

我在Matlab中遇到了语法问题。

我正在尝试将音频信号分成不同的段(帧)。

我想将y轴值返回到矩阵(每个段具有其自己的列),以及相应的时间值,每个段具有其自己的行。

我甚至不能让它只返回一个列和行对(即一帧)。 我刚回来两个空矩阵。 这是我的代码。

function [mFrames, vTimeFrame] = Framing(vSignal,samplingRate,frameLPerc,frameshPerc) totalTime=size(vSignal,1)/samplingRate frameLength = totalTime*frameLPerc; frameShift = totalTime*frameshPerc; frameNumber =0; check=frameLPerc; while check<1 check = check+frameshPerc; frameNumber=frameNumber+1; end start = 1; % problem part mFrames = vSignal(round((start:1/samplingRate:frameLength)*samplingRate)); vTimeFrame = round((start:1/samplingRate:frameLength)*samplingRate); end

最后,我希望能够将我的整个信号分成mFrames(i)和vTimeFrame(i),并使用for循环,但不要紧,我甚至不能让我的函数返回第一个(就像我说的那样)矩阵)。

我知道我的段代码应该是正确的,因为我有另一个脚本使用相同的vSignal(顺便说一下它是一个列向量),工作得很好(y == vSignal):

voiced = y(round((1.245:1/Fs:1.608)*Fs)); plot(1.245:1/Fs:1.608,voiced)

我用语法问题命名这个,因为我对matlab很新,而且习惯了Java。 没有初始化任何东西感觉很奇怪,所以我不确定我的代码是否真的有意义。

测试时,我输入[m1,m2] = Framing(y,16000,0.1,0.05)。

I'm having trouble with the syntax in Matlab.

I'm trying to split an audio signal up into different segments (frames).

I would like to return the y-axis values to a matrix (each segment having its own column), and the corresponding time values with each segment having its own row.

I can't even get it to return just one single column and row pair (ie one frame). I just get returned two empty matrices. Here's my code.

function [mFrames, vTimeFrame] = Framing(vSignal,samplingRate,frameLPerc,frameshPerc) totalTime=size(vSignal,1)/samplingRate frameLength = totalTime*frameLPerc; frameShift = totalTime*frameshPerc; frameNumber =0; check=frameLPerc; while check<1 check = check+frameshPerc; frameNumber=frameNumber+1; end start = 1; % problem part mFrames = vSignal(round((start:1/samplingRate:frameLength)*samplingRate)); vTimeFrame = round((start:1/samplingRate:frameLength)*samplingRate); end

In the end I would like to be able to segment my entire signal into mFrames(i) and vTimeFrame(i) with a for-loop, but never mind that I cannot even get my function to return the first one (like I said empty matrix).

I know my segment code should be correct because I've got another script working with the same vSignal (it's a column vector by the way) that works just fine (y==vSignal):

voiced = y(round((1.245:1/Fs:1.608)*Fs)); plot(1.245:1/Fs:1.608,voiced)

I titled this with syntax problems because I'm very new to matlab and am used to Java. It feels very weird not initializing anything, and so I'm unsure whether my code is actually making any sense.

When testing I enter [m1,m2]=Framing(y,16000,0.1,0.05).

最满意答案

我知道了。

开始不在正确的领域。 这是对的:

轮((开始/采样速率:1 /采样速率:帧长度)*采样速率)

当我绘制(m2,m1)时,我现在得到了正确的答案。

我还有另外一个问题,我怎样才能将这些段分配给我的矩阵?

for i=1:frameNumber mFrames(:,i) = vSignal(round((start/samplingRate:1/samplingRate:frameLength)*samplingRate)); vTimeFrame(i) = round((start/samplingRate:1/samplingRate:frameLength)*samplingRate); start=start+frameShift; frameLength=frameLength+frameShift; end

我收到这个错误

In an assignment A(I) = B, the number of elements in B and I must be the same.

就像我说的那样,我试图将y轴数字放在彼此相邻的列中,将x轴放在行中。

I got it.

start was not in the right domain. This is correct:

round((start/samplingRate:1/samplingRate:frameLength)*samplingRate)

When I plot(m2,m1) I now get the correct answer.

I do still have another question though, how can I assign these segments to my matrices?

for i=1:frameNumber mFrames(:,i) = vSignal(round((start/samplingRate:1/samplingRate:frameLength)*samplingRate)); vTimeFrame(i) = round((start/samplingRate:1/samplingRate:frameLength)*samplingRate); start=start+frameShift; frameLength=frameLength+frameShift; end

I get this error

In an assignment A(I) = B, the number of elements in B and I must be the same.

Like I said I'm trying to get the y-axis numbers in columns next to each other and the x-axis in rows.

更多推荐

本文发布于:2023-07-22 12:10:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1219898.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:组分   矩阵   语法   函数   Assigning

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!