fprintf error with student Mac version 2013a
4 views (last 30 days)
Show older comments
I'm brand new to Matlab and working with code written by a colleague. Everything is fine until I try to save the output file, at which point I get the errors shown below. The program works fine (including saving) in 2012a and on a PC. fprintf is also supposed to be supported in this version. The portion of code around line 676 is also shown below. Please help! I need this to finish my dissertation and am in a serious time crunch... Thanks! Nina
ERRORS: Error using fprintf Invalid file identifier. Use fopen to generate a valid file identifier.
Error in Nina_Dynamic_Analysis3Repeat>do_saveData (line 676) fprintf(fid, 'Date_of_Analysis:\t%s\n\n', datestr(datenum(date),2));
Error in Nina_Dynamic_Analysis3Repeat (line 40) do_saveData
CODE: [saveFile,savePath] = uiputfile([saveFileID '_DynAysV3.asc'],'Save File As'); fid = fopen([savePath saveFile],'w');
% fprintf(fid, 'SubjectID:\t%s\n\n', subjectID); [NOTE: this is line 676] fprintf(fid, 'Date_of_Analysis:\t%s\n\n', datestr(datenum(date),2)); fprintf(fid, 'ContractNum\tTargetvel(dps)\tEMGStart(ms)\tTorqueStart(ms)\tIsoVelStart(ms)\tIsoVelEnd(ms)\tTimeofPeakTorque(ms)\tPeakIsoTorque(Nm)\tVelAtPeakIsoTorque(dps)\tAngleAtPeakIsoTorque(deg)\tTimetoPeakTorque(ms)\tEMGAtPeakIsoTorque(mV)\tPeakPower(W)\tIsovelocityTTI(Nm*ms)\tFullContractionTTI(Nm*ms)\tTimeofMaxRFD(ms)\tMaxAbsVolRFD(Nm/ms)\tMaxRelVolRFD(%%Peak/ms)\tIsoVelDuration(ms)\tTTTarget(ms)\tTimeofMaxIsoVelEMG(ms)\tMaxIsoVelEMG(mV)\tTorqueAtMaxIsoVelEMG(Nm)\tTimeofMaxContractEMG(ms)\tMaxContractEMG(mV)\tTorqueAtMaxContractEMG(Nm)\tEMGAreaIsoVel(mV*ms)\tEMGAreaContract(mV*ms)\tLagInTorqueDevelopement(ms)\tFieldingRateofActivation(mV/ms)\tFittedRateofActivation(mV/ms)\tIntegratedRateofActivation(mV)\tAverageIntegratedRateofActivation(mV)\n'); for i=1:length(trueTargetVelArray) fprintf(fid, '%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\n',i, trueTargetVelArray(i), startEMGIndexArray(i), startTorqueIndexArray(i), startIsoVelIndexArray(i), endIsoVelIndexArray(i), peakIsoTorqueTimeArray(i), peakIsoTorqueArray(i), velAtPeakIsoTorqueArray(i), angleAtPeakIsoTorqueArray(i), TimeToPeakArray(i), EMGAtPeakIsoTorqueArray(i), peakPowerArray(i),TTIIsoVelArray(i), TTIFullArray(i),maxAbsVolRFDIndexArray(i), maxAbsVolRFDArray(i), maxRelVolRFDArray(i), IsoVelContractDurationArray(i), timeToTargetVelArray(i), maxIsoVelEMGIndexArray(i), maxIsoVelEMGArray(i), TorqueatMaxIsoVelEMGArray(i), maxContractEMGIndexArray(i), maxContractEMGArray(i), TorqueatMaxContractEMGArray(i), areaEMGIsoVelArray(i), areaEMGFullContArray(i), lagInTorqueDevelopmentArray(i), FieldingRateOfActivationArray(i),fittedRateofActivationArray(i), intRateofActivationArray(i),aveIntRateofActivationArray(i)); end fclose(fid); end
0 Comments
Answers (1)
Walter Roberson
on 9 Oct 2013
Opening the file failed for some reason. Change
fid = fopen([savePath saveFile],'w');
to
thisfile = fullfile(savePath, saveFile)
[fid, msg] = fopen(thisfile, 'w');
if fid < 0
error(sprintf('failed to open output file "%s" because: %s', thisfile, msg));
end
0 Comments
See Also
Categories
Find more on Spreadsheets in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!