请教如何在使用matlab GPU时记录arrayfun中的循环迭代变量?

在使用Matlab 2017b的GPU功能时,遇到一个问题:在arrayfun中尝试记录循环变量z,但出现‘Array indexing is not supported’的错误。寻求解决方案,以便能将arrayfun内部的循环变量存入矩阵,进行后续处理。
摘要由CSDN通过智能技术生成

在下述代码中,我希望能记录arrayfun函数里面的循环变量z到一个矩阵中,以作进一步的操作。Matlab版本为2017b,代码运行报错为“Array indexing is not supported”。请各位大侠赐教如何才能解决这一问题。

clear all
clc
maxIterations=100;
gridSize=300;
xlim=[-0.75, -0.73];
ylim=[ 0.12,  0.14];
t=tic();
x=gpuArray.linspace(xlim(1), xlim(2), gridSize);
y=gpuArray.linspace(ylim(1), ylim(2), gridSize);
[xGrid,yGrid]=meshgrid(x,y);
Pos=gpuArray.zeros(maxIterations,1);
count=parent_fun(xGrid,yGrid,maxIterations,Pos);
count=gather(count);
gpuArrayfunTime=toc(t)
figure(1)
imagesc(x,y,count)
reset(gpuDevice(1))

%下面是用到的子函数。使用nested function的形式是希望能进行索引,但无效。
function result=parent_fun(xGrid,yGrid,maxIterations,Pos)
             function count=tar_fun(x0,y0)
                           z0=complex(x0,y0);
                           z=z0;
                           count=1;
                           while (count<=maxIterations) && (abs(z)<=2)
    
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值