Filter löschen
Filter löschen

How to use SPDX Licenseinformation in .mat matlab files?

2 Ansichten (letzte 30 Tage)
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?

Akzeptierte Antwort

Suvansh Arora
Suvansh Arora am 4 Nov. 2022
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 Kommentare
Jonas Stein
Jonas Stein am 6 Nov. 2022
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 am 7 Nov. 2022
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:

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Manage Products finden Sie in Help Center und File Exchange

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by