Dear Sir/Madam
I have written a code in MATLAB to run the AnalyzeTool for PointKinematic Analysis. I can generate the correct xml file and by loading this xml file into the OpenSim GUI, get the results. However, I want to run the analyze tool via my MATLAB code. When I add AnalyzeTool.run() in my code in order to run automatically in MATLAB, I cannot get the answer. I was wondering if any body could help me with this issue.
Thanks,
Mohammad
Analyze Tool run with MATLAB
- Mohammadhossein Akhavanfar
- Posts: 19
- Joined: Mon Oct 16, 2017 9:11 am
- Erica Beaucage-Gauvreau
- Posts: 49
- Joined: Fri Apr 03, 2015 2:12 am
Re: Analyze Tool run with MATLAB
Hi Mohammad,
This thread might be helpful:
viewtopicPhpbb.php?f=91&t=8467&p=23188&start=0&view=
Cheers,
Erica
This thread might be helpful:
viewtopicPhpbb.php?f=91&t=8467&p=23188&start=0&view=
Cheers,
Erica
- Mohammadhossein Akhavanfar
- Posts: 19
- Joined: Mon Oct 16, 2017 9:11 am
Re: Analyze Tool run with MATLAB
Hi Erica,
Thank you for your response. Actually, the thread didn't solve my problem. I don't have any problem to setup my analyze tool because I can generate the correct xml file. I mean my generated xml file contains everything we need for running the analyze tool and I got the result when I load it in OpenSim. Here is my code and I commented where my problem is:
Thank you for your response. Actually, the thread didn't solve my problem. I don't have any problem to setup my analyze tool because I can generate the correct xml file. I mean my generated xml file contains everything we need for running the analyze tool and I got the result when I load it in OpenSim. Here is my code and I commented where my problem is:
Code: Select all
myModel.initSystem();
analyzeTool=AnalyzeTool(PKtemplateFile);
analyzeTool.setModel(myModel);
analyzeTool.setModelFilename('Granata_Trunk');
initial_time=motData.getFirstTime();
final_time=motData.getLastTime();
analyzeTool.setInitialTime(initial_time);
analyzeTool.setFinalTime(final_time);
analyzeTool.setCoordinatesFileName(MotionFile);
analyzeTool.getAnalysisSet().get(0).setStartTime(initial_time)
analyzeTool.getAnalysisSet().get(0).setEndTime(final_time);
analysis=analyzeTool.getAnalysisSet().get(0);
analyzeTool.setSolveForEquilibrium(false);
analyzeTool.setMaximumNumberOfSteps(20000);
analyzeTool.setMaxDT(1);
analyzeTool.setMinDT(1e-008);
analyzeTool.setErrorTolerance(1e-005);
analyzeTool.setReplaceForceSet(false);
analyzeTool.setOutputPrecision(8);
pointkinematics=PointKinematics.safeDownCast(analysis);
pointkinematics.setModel(myModel);
for i=1:JointSize
attachpoint=Joints.get(i-1).getParentBody();
pointkinematics.setBody(attachpoint);
pointkinematics.setPointName(Jointnames{i});
ground= myModel.updBodySet().get('ground');
pointkinematics.setRelativeToBody(ground);
pointkinematics.setPoint(Jointlocation(i));
analyzeTool.setName('subject1');
results_directory=[ModelFilePath '\JPK\' Jointnames{i}];
analyzeTool.setResultsDir(results_directory);
setupFile=[Jointnames{i} '_' 'Subject1_setup_JPK.xml'];
analyzeTool.print([results_directory '\' setupFile ]);
%% up to this point of my code, I can generate the correct xml file
%%analyzeTool.run();
%%when I run, I get the results for NONAME point
%%but if I load the xml file in OpenSim, I get the results for actual points
end
- Josh Baxter
- Posts: 29
- Joined: Fri Mar 11, 2016 12:29 pm
Re: Analyze Tool run with MATLAB
i'd recommend running these tools by calling their commands thru the command line...
[success,output] = dos(['analyze -S ',xmlpath]);
this seems to run faster and the screen output is suppressed to variable output - which is convinient because a single fprintf(fid,output) writes the output cleanly to a txt file for later use (i think there are some weird characters that end up disappearing...)
give that a go.
[success,output] = dos(['analyze -S ',xmlpath]);
this seems to run faster and the screen output is suppressed to variable output - which is convinient because a single fprintf(fid,output) writes the output cleanly to a txt file for later use (i think there are some weird characters that end up disappearing...)
give that a go.