Matlab under Unix vs Win?
3 次查看(过去 30 天)
显示 更早的评论
Hi all,
When I run this code under Unix (Matlab 2015a), it takes forever without any result showing up, I checked the system monitor to see if the matlab is working inthe background or not I found the Matalb process is seelping as in the attached file!
I ran the same code under win (Matlab 2018), only a few minutes and I saw a msg that the matlab starts the parallel pool and it seems running , after a few minutes I received this error:
Error using rapid_accel_target_utils
Error occurred while simulating the model 'TwoVoltsTanhtestmodel2' in rapid accelerator mode. Rerun the simulation in normal mode to diagnose this
error.
Error in rapid_accel_target_utils
Error in sl (line 15)
[varargout{1:nargout}]=feval(varargin{:});
Error in testscript21 (line 121)
parfor(i = 1:numSimCmdArgStructs)
Could someone explain why this happen under Unix, although before it was fine, this is a new issue.
Thank you in advance,
The code is :
load('matlab')
mdl = 'TwoVoltsTanhtestmodel2';
%imageData=[1,-1,-1,-1,1;-1,1,-1,1,-1;-1,-1,1,-1,-1;-1,1,-1,1,-1;1,-1,-1,-1,1];
%imageData=[-1,-1,1,-1,-1;-1,-1,1,-1,-1;1,1,1,1,1;-1,-1,1,-1,-1;-1,-1,1,-1,-1];
I = imread('/home/salibensuleiman/Documents/MATLAB/Escher/Escher/DrowImg1.png');
% I1=imcomplement(I);
ResizedImage = imresize(I, [10 10]);
level = graythresh(ResizedImage);
BW = im2bw(I,level);
%A = BW(1:100,1:100);
imageData = int8(BW);
for i=1:10
for j=1:10
if(imageData(i,j)==0 )
imageData(i,j)=1;
else if ( imageData(i,j)==1)
imageData(i,j)=-1;
end
end
end
end
U=zeros(12,12);
Y=zeros(12,12);
for i=2:11
for j=2:11
U(i,j)=imageData(i-1,j-1);
end
end
PartialArray=zeros(3,3,100);
PartialY=zeros(3,3,100);
d=0;
k=1;
page=0;
for i =1:10
for j=1:10
page=page+1;
for row=i:i+2
d=d+1;
for col=j:j+2
PartialArray(d,k,page)=U(row,col);
PartialY(d,k,page)=Y(row,col);
k=k+1;
end
k=1;
end
d=0;
end
end
numParamSets = 100;
% Create parameter sets:
assignin('base',['Y11ini' ],0);
assignin('base',['Y12ini' ],0);
assignin('base',['Y13ini' ],0);
assignin('base',['Y21ini' ],0);
assignin('base',['Y22ini' ],0);
assignin('base',['Y23ini' ],0);
assignin('base',['Y31ini' ],0);
assignin('base',['Y32ini' ],0);
assignin('base',['Y33ini' ],0);
paramSets = cell(1, numParamSets);
idx = 1;
M = Simulink.BlockDiagram.buildRapidAcceleratorTarget(mdl);
for page = 1:100
paramSets{idx} = Simulink.BlockDiagram.modifyTunableParameters(...
M,...
'U11',PartialArray(1,1,page),...
'U12',PartialArray(1,2,page),...
'U13',PartialArray(1,3,page),...
'U21',PartialArray(2,1,page),...
'U22',PartialArray(2,2,page),...
'U23',PartialArray(2,3,page),...
'U31',PartialArray(3,1,page),...
'U32',PartialArray(3,2,page),...
'U33',PartialArray(3,3,page),...
'Y11ini',PartialY(1,1,page),...
'Y12ini',PartialY(1,2,page),...
'Y13ini',PartialY(1,3,page),...
'Y21ini',PartialY(2,1,page),...
'Y22ini',PartialY(2,2,page),...
'Y23ini',PartialY(2,3,page),...
'Y31ini',PartialY(3,1,page),...
'Y32ini',PartialY(3,2,page),...
'Y33ini',PartialY(3,3,page));
idx = idx+1;
end
numSimCmdArgStructs = numParamSets;
simCmdParamValStructs = cell(1, numSimCmdArgStructs);
paramValStruct.SaveTime = 'on';
paramValStruct.SaveOutput = 'on';
paramValStruct.SimulationMode = 'rapid';
paramValStruct.RapidAcceleratorUpToDateCheck = 'off';
paramValStruct.RapidAcceleratorParameterSets = [];
paramValStruct.LimitDataPoints = 'off';
idx = 1;
for paramSetsIdx = 1:numParamSets
simCmdParamValStructs{idx} = paramValStruct;
simCmdParamValStructs{idx}.RapidAcceleratorParameterSets = paramSets{paramSetsIdx};
idx = idx + 1;
end
Yout=zeros(100,1,100);
out = cell(1, numSimCmdArgStructs);
l=1;
%for l=1:2
parfor(i = 1:numSimCmdArgStructs)
out{i} = sim(mdl, simCmdParamValStructs{i});
end
for i=1:numSimCmdArgStructs
t = out{i}.find('tout');
y = out{i}.find('Y22');
PartialY(2,2,i)=y(end);
Yout(i,1,l)=y(end);
end
out = cell(1, numSimCmdArgStructs);
%end
disp('done')
fprintf('\n Contents of the out{1}: \n');
display(out{1});
displayEndOfDemoMessage(mfilename)
g=1;
% % for g=1:5
figure(g)
z=((reshape(Yout(:,:,g),[10,10])));
z1=imshow(z);
hold on;
%end
3 个评论
OCDER
2019-1-15
% Create parameter sets:
assignin('base',['Y11ini' ],0);
assignin('base',['Y12ini' ],0);
assignin('base',['Y13ini' ],0);
assignin('base',['Y21ini' ],0);
assignin('base',['Y22ini' ],0);
assignin('base',['Y23ini' ],0);
assignin('base',['Y31ini' ],0);
assignin('base',['Y32ini' ],0);
assignin('base',['Y33ini' ],0);
What is the purpose of the assignin? assignin should be avoided as it's "poofing" variables into another workspace, making it difficult to debug.
Guillaume
2019-1-15
I've formatted the code in the question. Please learn to use the formatting tool to make your post readable.
In addition to OCDER comment, in the same lines, the [] are completely unnecessary and just visual clutter.
采纳的回答
更多回答(1 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Loops and Conditional Statements 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!