Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-core/3.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
C++ 使用Parfor从向量创建矩阵_C++_Matlab_For Loop_Iteration_Parfor - Fatal编程技术网

C++ 使用Parfor从向量创建矩阵

C++ 使用Parfor从向量创建矩阵,c++,matlab,for-loop,iteration,parfor,C++,Matlab,For Loop,Iteration,Parfor,我是Matlab新手,非常感谢您的帮助 我正在运行模拟,因此每次运行模拟的结果都会有所不同。我想收集分析结果 例如,在第一次模拟运行期间,血浆凝血因子的水平可能在5小时内发生变化,如下所示: R(1)=[1.0 0.98 0.86 0.96 0.89] 在第二次运行中,每个时间段的水平可能略有不同,例如。 R(2)=[1.0.95 0.96 0.89 0.86] 我想(也许通过使用parfor函数)创建一个矩阵,例如。 R=[1.0.98 0.86 0.96 0.89 1.0.95 0.96 0

我是Matlab新手,非常感谢您的帮助

我正在运行模拟,因此每次运行模拟的结果都会有所不同。我想收集分析结果

例如,在第一次模拟运行期间,血浆凝血因子的水平可能在5小时内发生变化,如下所示: R(1)=[1.0 0.98 0.86 0.96 0.89]

在第二次运行中,每个时间段的水平可能略有不同,例如。 R(2)=[1.0.95 0.96 0.89 0.86]

我想(也许通过使用parfor函数)创建一个矩阵,例如。 R=[1.0.98 0.86 0.96 0.89 1.0.95 0.96 0.89 0.86]

我遇到的问题从“在赋值A(I)=B中,B和I中的元素数量必须相同”到得到一个由0或1组成的矩阵(取决于我在预分配中使用的内容)

我需要模拟运行大约10000次,以便收集有意义的结果

有人能建议如何实现这一目标吗?一个详细的指导或(半)完整的代码将非常感谢像我这样的Matlab新手

提前谢谢

这是我的实际代码,如您所见,有4个变量在744小时(31天)内变化,我想单独收集:

Iterations = 10000;
PGINR = zeros(Iterations, 744);
PGAmount = zeros(Iterations, 744);
CAINR = zeros(Iterations, 744);
CAAmount = zeros(Iterations, 744);

for iii = 1:Iterations
    [{PGINR(iii)}, {PGAmount(iii)}, {CAINR(iii)}, {CAAmount(iii)}] = ChineseTTRSimulationB();
end

filename = 'ChineseTTRSimulationResults.xlsx';
xlswrite(filename, PGINR, 2)
xlswrite(filename, PGAmount, 3)
xlswrite(filename, CAINR, 5)
xlswrite(filename, CAAmount, 6)

你在找这样的东西吗? 为了更好地理解,我简化了一些代码,并添加了一些虚拟数据和函数

main.m

Iterations  = 10;
PGINR       = zeros(Iterations, 2);
PGAmount    = zeros(Iterations, 2);

%fake data
x = rand(Iterations,1);
y = rand(Iterations,1);

parfor iii = 1:Iterations
    [PGINR(iii,:), PGAmount(iii,:)] = ChineseTTRSimulationB(x(iii), y(iii));
end
function [PGINRi, PGAmounti] = ChineseTTRSimulationB(x,y)
    PGINRi       = [x + y, x];
    PGAmounti    = [x*y, y];
end
ChineseTTRSimulationB.m

Iterations  = 10;
PGINR       = zeros(Iterations, 2);
PGAmount    = zeros(Iterations, 2);

%fake data
x = rand(Iterations,1);
y = rand(Iterations,1);

parfor iii = 1:Iterations
    [PGINR(iii,:), PGAmount(iii,:)] = ChineseTTRSimulationB(x(iii), y(iii));
end
function [PGINRi, PGAmounti] = ChineseTTRSimulationB(x,y)
    PGINRi       = [x + y, x];
    PGAmounti    = [x*y, y];
end

将每个parfor结果保存在单元格中,稍后再合并它们

Iterations = 10000;
PGINR = cell(1, Iterations);
PGAmount = cell(1, Iterations);
CAINR = cell(1, Iterations);
CAAmount = cell(1, Iterations);

parfor i = 1:Iterations
    [PGINR{i}, PGAmount{i}, CAINR{i}, CAAmount{i}] = ChineseTTRSimulationB();
end

PGINR = cell2mat(PGINR); % 1x7440000 vector
%and so on...

亲爱的兰帕,非常感谢你的建议!我将尝试它,只要我的当前模拟已经完成运行!亲爱的Arpi,非常感谢您的建议!我将尝试它,只要我的当前模拟已经完成运行!