필터 지우기
필터 지우기

How to use SPDX Licenseinformation in .mat matlab files?

조회 수: 2 (최근 30일)
Jonas Stein
Jonas Stein 2022년 11월 1일
댓글: Suvansh Arora 2022년 11월 7일
SPDX is an ISO standard which enables one to add structured human and machine readabel license information to files.
I do not want to clutter the preview function of matlab.
How should the SPDX information be added to the file?
Is it possible to tell matlab, that comments with SPDX data should be ignored in the preview?

채택된 답변

Suvansh Arora
Suvansh Arora 2022년 11월 4일
I think the “preview” function you are talking about is the “help” function that is used to provide help for the programs you write.
I would like to recommend a way to not clutter the help data with unwanted license information.
  • Add a space in between the license information and documentation in your code
function c = addMe(a,b)
% ADDME Add two values together.
% C = ADDME(A) adds A to itself.
%
% C = ADDME(A,B) adds A and B together.
%
% See also SUM, PLUS.
% License information:
switch nargin
case 2
c = a + b;
case 1
c = a + a;
otherwise
c = 0;
end
>> help addME % In order to view the documentation.
addMe Add two values together.
C = addMe(A) adds A to itself.
C = addMe(A,B) adds A and B together.
See also sum, plus.
I hope the above information helps you.
  댓글 수: 2
Jonas Stein
Jonas Stein 2022년 11월 6일
Does the following pseudo code cover all cases?
FOR ALL .mat FILES DO
IF there_is_a_function
THEN add_spdx_comment_before_function
ELSE add_spdx_comment_in_first_lines_of_the_file
Suvansh Arora
Suvansh Arora 2022년 11월 7일
A better way of achieving this would be:
FOR ALL .mat FILES DO
IF there_is_a_function
THEN
skip_lines_with_comments
Add_space_and_add_spdx_information_as_a_comment
ELSE
skip_lines_with_comments
Add_space_and_add_spdx_information_as_a_comment
  • “skip_lines_with_comments”: This will be useful in having a “help” output of the functions/scripts.
  • “Add_space_and_add_spdx_information_as_a_comment”: Adding space would break the “help” output and the comments further on can be used to add “spdx” information.
In order to achieve above automation, you can follow the ML answers article mentioned below:

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Manage Products에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by