필터 지우기
필터 지우기

How to solve spmd problem

조회 수: 3 (최근 30일)
cemsi888
cemsi888 2016년 9월 10일
답변: Walter Roberson 2016년 9월 10일
Hi guys
i am programming kuka robot. I would like to obtain datas with arduino. That is why I am usuing paralel functions.However, I have problem and I do not know whether it is about spmd or not.
The error ='"i" previously appeared to be used as a function or command, conflicting with its use here as the name of a variable.
A possible cause of this error is that you forgot to initialize the variable, or you have initialized it implicitly using load or eval.'
I did not use i as a function but I load variable.mat to call i. Following I add my codes...
%%%Main program
function data = main
PointList.PointID = [1,2,3,4,5];
PointList.X = [1000,1100,1200,1250,1300];
PointList.Y = [0,0,0,0,0];
PointList.Z = [1400,1450,1455,1470,1500];
PointList.A = [-159.84,-159.84,-159.84,159.84,159.84];
PointList.B = [89.93,89.93,90,98,98];
PointList.C = [-160.05,160.05,160.05,160.05,160.05];
funList = {@fun1,@fun2};
dataList = {PointList,PointList}; % or pass file names
matlabpool ('local',2)
spmd
labBarrier
Daten1 = funList{labindex}(dataList{labindex});
end
data = {Daten1{:}};
and now fun 1
function [PointID] = fun1(PointList)
....
load variablen_1
...
if posreached (RIst, RSol, i) == 1
Counter = IPOC(i);
while IPOC(i) < Counter+2000
Ein=H.Ein(2);
Aus=H.Aus(1);
reply = ['<Sen Type="ImFree"><EStr>' Msg '</EStr>'...
'<Tech T21="0.0" T22="0.0" T23="0.0" T24="0.0" T25="0.0" T26="0.0" T27="0.0" T28="0.0" T29="0.0" T210="0.0" />'...
'<Pos X="' num2str(X) '" Y="' num2str(Y) '" Z="' num2str(Z) '"'...
'A="' num2str(A) '" B="' num2str(B) '" C="' num2str(C) '"/>'...
'<Speed>' num2str(speed) '</Speed><Waittime>' num2str(waittime) '</Waittime>'...
'<Mode>' num2str(mode) '</Mode><Point_ID>' num2str(hPoint) '</Point_ID>'...
'<Spindel Ein="' num2str(Ein) '" Aus="' num2str(Aus) '"/>'...
'<Drehzahl>' num2str(Drehzahl) '</Drehzahl>'...
'<IPOC>' num2str(RIst.IPOC(end)) '</IPOC></Sen>' ];
fwrite(con,double(reply)); %Schickt Antwort an Roboter zurück
i=i+1;
end
i cut some codes. As you see I used i as an input in another function too. I did not get any errors on these lines just on i=i+1
Do you have any idea?
Thanxx

답변 (1개)

Walter Roberson
Walter Roberson 2016년 9월 10일
By default i and j are functions that return sqrt(-1) . But inside fun1 you have i=i+1 indicating that you think i is a variable instead of a function. Where did that variable come from?
If your answer is that you are loading i from the .mat file and having it magically appear in the workspace, then "Don't do that!" . Instead, use
datastruct = load('variablen_1');
i = datastruct.i;
... and keep in mind that it is always going to be the same value of i that is loaded since you are not writing to variablen_1.mat in your code. Your code would be clearer and more efficient if you were to do the load() once in main and pass i as a parameter to fun1

카테고리

Help CenterFile Exchange에서 Arduino Hardware에 대해 자세히 알아보기

태그

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by