How do I load text stored in an external file and display it as an annotation in a Simulink models?
조회 수: 2 (최근 30일)
이전 댓글 표시
I like to include lots of annotations in my model files that clearly describe what's going on in a visible way (without having to click to open documents or open links etc). However, our technical publications guys need to review, edit, spell-check etc any documentation - but obviously don't want to edit and resave MDL files, in case they break something.
I'd therefore like some way of giving them a separate file to review for a model containing the text for all the annotations (perhaps an xml file) but pre-load this to populate the annotation text in my model.
Any ideas how I might do this? PreLoadFcn callbacks & xmlreads?
댓글 수: 0
채택된 답변
Fangjun Jiang
2011년 5월 13일
It is relatively easy to export all the annotations in your model to a text file for others to review. After the review is done, I assume you want the modified text to be automatically loaded back to your model. This is a little tricky because there is no built-in function to link the text in your text file to the annotations in your model, with absolutely correct one-to-one match.
The key is to make sure the one-to-one match. To do that, you need to first assign your annotations a unique ID.
a=find_system(Model,'FindAll','On','Type','annotation');
for i=1:length(a)
set(a(i),'UserData',i,'UserDataPersistent','On');
end
save_system(Model);
xlswrite('ForReview.xls',[get(a,'UserData'),get(a,'Name')]);
You can give the Excel file for others to review and take the updated file back. Try not to mess up with the ID numbers.
[ID,Annotation]=xlsread('ForReview.xls');
a=find_system(Model,'FindAll','On','Type','annotation');
for i=1:size(a)
[Found,Index]=ismember(get(a(i),'UserData'),ID);
if ~Found
error('No matching ID found in text file.');
else
set(a(i),'name',Annotation(Index));
end
end
save_system(Model);
If you don't want to leave those ID, run set(a,'UserData',[]) before save_system.
Use some caution, it should be able to solve your problem.
댓글 수: 2
Fangjun Jiang
2011년 5월 23일
Sorry! I just realized that the attribute 'UserDatPersistent' needs to be set as 'On' to save the UserData with the .mdl file.
추가 답변 (1개)
MarkB
2011년 5월 17일
One possible way to do this is to use a mask on top of an empty subsystem instead of annotations. From there, you can use the mask drawing commands to add arbitrary text as the display for the block.
However, this isn't particularly elegant because there isn't very much variety in what you can do to format the text, and the block doesn't resize to fit the text either.
If you can tolerate a few additional clicks in your process, it might be better to combine a masked, empty subsystem with documentation stored in an HTML file. You can use the "web" command in the mask's help dialog to cause it to open the HTML file in a separate window.
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Interactive Model Editing에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!