Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/matlab/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Matlab 持久变量模拟_Matlab_Functional Programming_Signal Processing_Simulink_Persistent - Fatal编程技术网

Matlab 持久变量模拟

Matlab 持久变量模拟,matlab,functional-programming,signal-processing,simulink,persistent,Matlab,Functional Programming,Signal Processing,Simulink,Persistent,我试图使用持久变量将以前的样本存储在嵌入式Matlab函数中。在每一步中,我都会得到一个32位的输入,并将其存储到持久变量中。作为嵌入式Matlab函数的一个输出,一旦采集了模拟时间的所有样本,我将尝试将其发送到调制器。问题如下:使用随机整数生成器(假设模拟时间为0.01s),该块生成626个整数,然后在嵌入式Matlab函数中扩展到626x32位。现在,这个626x32是我当前嵌入的带有持久变量的matlab函数的输入。我期望的输出是(626*32)x1,但我得到的输出是626x(626*32

我试图使用持久变量将以前的样本存储在嵌入式Matlab函数中。在每一步中,我都会得到一个32位的输入,并将其存储到持久变量中。作为嵌入式Matlab函数的一个输出,一旦采集了模拟时间的所有样本,我将尝试将其发送到调制器。问题如下:使用随机整数生成器(假设模拟时间为0.01s),该块生成626个整数,然后在嵌入式Matlab函数中扩展到626x32位。现在,这个626x32是我当前嵌入的带有持久变量的matlab函数的输入。我期望的输出是(626*32)x1,但我得到的输出是626x(626*32),也就是说,我希望避免出现重复的行。有人能帮我吗。这是我的密码

function y = fcn(u)
%#codegen
persistent temp_store;
persistent n;
Tsim = 0.01;
sample_time = 1.6e-5;
no_of_chips = 32;
no_of_samples = round(Tsim/sample_time);

if isempty(n) %%initialize persistent variable
    n = 1;
end

if isempty(temp_store) %%initialize persistent variable
temp_store = zeros(no_of_samples * no_of_chips,1);
end

 %%storing samples into persistent variable
 while(n <= no_of_samples)      
    temp_store((n * no_of_chips)-(no_of_chips - 1): n * no_of_chips) = u;
    n = n + 1;       
 end

 %% After collection of all samples, output the persistent variable
    if(n == no_of_samples + 1)
        y = uint8(temp_store);  

    else
        y = uint8(zeros(no_of_samples * no_of_chips,1));
    end
end
函数y=fcn(u)
%#编码基因
持久性温度存储;
宿存氮;
Tsim=0.01;
采样时间=1.6e-5;
_芯片的_数量=32;
样本数量=整轮(Tsim/样本数量/时间);
如果为空(n)%%,则初始化持久变量
n=1;
结束
如果为空(临时存储)%%初始化持久变量
温度存储=零(样本数量*芯片数量,1);
结束
%%将样本存储到持久变量中

而(n)如果我在MATLAB中运行这个函数,我得到20000x1,大约是626x32。你是如何得到626x626x32的?u的大小是多少?我在MATLAB中得到相同的结果(20000x1)但是,当我在嵌入式matlab函数中运行Simulink模型中的相同代码,并查看输出时,我得到626x20000。u的大小是636x32。好的,如果每个时间步的输入是626x32,那么每个时间步的输出也是626x32。看起来Simulink解算器需要626个时间步。您使用的解算器和时间步是什么?我是我使用的采样时间为1.6e-5,我使用的是ode45解算器。但是,我在工作区中收到以下警告:“模型没有连续状态,因此Simulink使用解算器“VariableStepDiscrete”而不是解算器“ode45”。”'