fprintf of multidimensional cell arrays

조회 수: 1 (최근 30일)
Jamie Wardlaw
Jamie Wardlaw 2013년 12월 4일
답변: Jamie Wardlaw 2013년 12월 4일
Hello,
I am working on an export script to extract requirements references from my model to a simple XML file that I then post process using perl. the requirements references are simple text added as annotations to a block within the locality of the functionality. The script works until I have multiple requirements referenced on one annotation on separate lines. The problem seems to stem from the return of a cell array (1x3).
Here is the script:
% code
reqrefs = find_system('Regexp','on','AttributesFormatString','m:');
reqtxt = get_param(reqrefs,'AttributesFormatString');
reqstr = 'm:([0-9]+\.[A-Z]+\.[A-Z]+\.[0-9]+\.v[0-9]+)';
reqs = regexp(reqtxt,reqstr,'match');
fileID = fopen('~reqrefs.txt','wt');
fprintf(fileID,'%s\n','<SLX>');
for i = 1:length(reqrefs)
fprintf(fileID,'\t<XREF>\n\t\t<ID>%s</ID>\n\t\t<SYS>%s</SYS>\n\t</XREF>\n',char(reqs{i}),reqrefs{i});
sys(i).reqxref = reqs{i};
sys(i).location = reqrefs(i);
end
fprintf(fileID,'%s','</SLX>');
fclose(fileID);
The output from the script is in the attached file. At line 32 you can see how the multi-lined annotation is output to the file. Can anyone help me change my fprintf statement to handle to the cell array correctly?
Thanks
Jamie
  댓글 수: 1
Jamie Wardlaw
Jamie Wardlaw 2013년 12월 4일
Coming back to this with fresh eyes I found the solution, my for loop has been changed to parse the cell array as follows
if true
% code
for i = 1:length(reqrefs)
reqids = reqs{i};
[nrows,ncols]=size(reqids);
for col=1:ncols
fprintf(fileID,'\t<XREF>\n\t\t<ID>%s</ID>\n\t\t<SYS>%s</SYS>\n\t</XREF>\n',char(reqids{:,col}),reqrefs{i});
end
end
The text is now correctly extracted from the model on multi-lines of the annotation.

댓글을 달려면 로그인하십시오.

채택된 답변

Jamie Wardlaw
Jamie Wardlaw 2013년 12월 4일
My answer is above

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Programmatic Model Editing에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by