扩展MATLAB函数名称的最大长度 [英] Extending the maximum length of MATLAB function names

查看:984
本文介绍了扩展MATLAB函数名称的最大长度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写了一个MATLAB程序,用于创建自定义MATLAB函数,并使用 unix 命令在其他MATLAB实例中启动它们。我使用该程序进行fMRI神经影像分析自动化(使用SPM8 for MATLAB),并且一切正常。但是,MATLAB规定一个最大长度为63个字符的函数名称长度( namelengthmax )。由于我需要在每个函数名称中保存两个不同的时间戳以及创建它的函数的名称(我有几个不同的函数可以创建这些用于多线程功能磁共振成像分析的新函数),因此63个字符对文件名非常有限:



atf_2012_07_05_18_01_02_specify_1st_level_2012_07_05_18_10_15.m



在这个例子中 atf 表示'分析线程函数'(将线程与其他具有相似文件名的文件分开),第一个时间戳标识运行时间(全局时间戳,它是这种情况2012年7月5日在18:01:02),然后有一个字符串 specify_1st_level 来标识函数(在这种情况下 specify_1st_level.m ),它创建了这个新的分析线程函数,然后第二个时间标记从其他新创建的分析线程函数中标识出这个特定的新分析线程函数,以便在其他线程中运行不同分析主题或不同分析),并同时运行。



我的问题是函数名称的字符数限制为63个字符。



我知道我可以写下没有下划线( _ )的时间戳,或者压缩它们,而我可以使我的函数名称缩短(例如。 specify_1st_level.m - > sp1st.m ),并且我可以将我在飞行中创建的函数划分到不同的子文件夹中也创建在飞行命名如。与全球时间戳。 编辑:或者我甚至可以创建整个函数名称的散列,并使用散列作为函数名称,而不是上面提供的人类可读字符串。然而,我打算在'分析线程函数'的名称中添加更多数据(在这次运行中使用的不同分析参数集的一个或多个哈希值来标识相同的分析不同的时间)。如果可能的话,我希望保持它的好和简单(人类可读的函数名称有助于调试在运行中创建的'分析线程函数')。

那么,有什么方法可以扩展 namelengthmax 我在Linux中运行MATLAB R2012a。我也很高兴听到任何其他方式来解决这个问题。

解决方案

回答我自己的问题:更多的是,我找到了一种方法将尽可能多的信息嵌入MATLAB函数名称中,并且仍然保持对人类的可读性。首先,我将计算函数文件名的SHA1哈希值:的SHA1哈希值atf_2012_07_05_18_01_02_specify_1st_level_2012_07_05_18_10_15.m E545831A 0002C73B CA095F11 25FC5C51 35B82451 (这里用空格表示)。

然后我的函数名将是 ['atf_',sha1hashString,'.m'] ,对于这个例子,这个例子将会是 atf_E545831A0002C73BCA095F1125FC5C5135B82451.m ,所以函数名长度将是44个字符,这完全没有问题。这解决了63个字符的限制,但我还需要一种方法来使用常规的bash命令来查找我的函数。

所以我将创建一个副本函数文件,将散列连接到原始函数名称的末尾,因此它变成 atf_2012_07_05_18_01_02_specify_1st_level_2012_07_05_18_10_15_E545831A0002C73BCA095F1125FC5C5135B82451.m 。然后,我可以使用 ls find (用于调试目的)轻松地在bash中找到正确的函数,在MATLAB调试器中设置断点,并在MATLAB函数中设置断点(例如 atf_E545831A0002C73BCA095F1125FC5C5135B82451.m )并使用MATLAB调试器。



这是我能想到的最实用的解决方案,它也可以将分析参数集的哈希值添加到函数名称中:我将计算分析的SHA1哈希值参数集(让我们假设参数集的SHA1哈希是 A9993E36 4706816A BA3E2571 7850C26C 9CD0D89D ,并与原始函数名称连接,它将会是 atf_2012_07_05_18_01_02_specify_1st_level_2012_07_05_18_10_15_A9993E364706816ABA3E25717850C26C9CD0D89D .m 。然后,我将计算一个新的SHA1散列,这个原始函数名用分析参数集的SHA1散列扩展s:的SHA1哈希值atf_2012_07_05_18_01_02_specify_1st_level_2012_07_05_18_10_15_A9993E364706816ABA3E25717850C26C9CD0D89D.m A81F0083 38868103 F1A0DB69 010279D5 5DB3751E 。然后,我将创建两个相同的功能,一个是MATLAB,一个用于调试我的目的,他们将被命名为 atf_A81F008338868103F1A0DB69010279D55DB3751E.m atf_2012_07_05_18_01_02_specify_1st_level_2012_07_05_18_10_15_A9993E364706816ABA3E25717850C26C9CD0D89D_A81F008338868103F1A0DB69010279D55DB3751E.m 。甚至可以通过这种方式将不同参数的多个SHA1散列设置为相同的函数名称,例如。一个定义要包含的主题,另一个定义数据处理参数等,然后将它们两者或全部连接到文件名,然后计算SHA1哈希并编写两个与上面相同的函数。


I have a written a MATLAB program that creates custom MATLAB functions on the fly and launches them in other MATLAB instances using unix command. I use this program for automatizing fMRI neuroimaging analyses (using SPM8 for MATLAB), and everything works fine. However, MATLAB imposes a function name length maximum of 63 characters (namelengthmax). As I need to save two different timestamps in each function name together with the name of the function that created it (I have several different functions that create these new functions that are used for multithreaded fMRI analysis), 63 characters is quite limiting for filenames like:

atf_2012_07_05_18_01_02_specify_1st_level_2012_07_05_18_10_15.m

In this example atf means 'analysis thread function' (to separate it from other files with similar filenames), the first timestamp identifies the run (a global timestamp, it this case 5th of July 2012 at 18:01:02), then there's a string specify_1st_level that identifies the function (in this case specify_1st_level.m) that created this new 'analysis thread function', and then the second time stamp identifies this specific new 'analysis thread function' from other new 'analysis thread functions' created to be run in other threads (and for different analysis subjects, or for different analyses) and that are run simultaneously.

My problem is the character limit of 63 characters for function names.

I'm aware that I could write my timestamps without underscores (_), or compress them, and I can make my function names shorter (eg. specify_1st_level.m -> sp1st.m), and also I could divide my functions created on the fly in different subfolders also created on the fly named eg. with global timestamps. Edit: Or I could even create a hash of the entire function name and use the hash as a function name instead of the human-readable string presented above.

However, I plan to add more data in the names of 'analysis thread functions' (one or more hash values of different analysis parameter sets used in this run to identify identical analyses of different times). If possible, I would like to keep it nice and simple (human-readable function names help in debugging of 'analysis thread functions' created on the fly).

So, is there any way to extend namelengthmax ? I'm running MATLAB R2012a in Linux. I'm also happy to hear any other ways to solve this issue.

解决方案

Answering to my own question: After thinking it some more, I found a way to embed as much information as I want into a MATLAB function name and still keep it readable for humans. First, I'll compute SHA1 hash of my function filename: SHA1 hash of atf_2012_07_05_18_01_02_specify_1st_level_2012_07_05_18_10_15.m is E545831A 0002C73B CA095F11 25FC5C51 35B82451 (here presented with spaces for clarity).

Then my function name will be [ 'atf_', sha1hashString, '.m' ], for this example that'll be atf_E545831A0002C73BCA095F1125FC5C5135B82451.m, so the function name length will be 44 characters, that's no problem at all. This solves the limitation of 63 characters, but I also need a way to be able to find my functions using regular bash commands.

So I'll create a copy of that function file, concatenating the hash to the end of the original function name, so it becames atf_2012_07_05_18_01_02_specify_1st_level_2012_07_05_18_10_15_E545831A0002C73BCA095F1125FC5C5135B82451.m. Then I can find the correct function easily in bash using ls or find (for debugging purposes), check the hash from the end of the filename and set breakpoint in MATLAB debugger in the function that will be called from MATLAB (eg. atf_E545831A0002C73BCA095F1125FC5C5135B82451.m) and use MATLAB debugger without problems.

This is the most practical solution I can think of and it makes possible to add hashes of analysis parameter sets into the function name too: I'll just compute the SHA1 hash of the analysis parameter set (let's assume that the SHA1 hash of the parameter set is A9993E36 4706816A BA3E2571 7850C26C 9CD0D89D, and concatenated with original function name it'll be atf_2012_07_05_18_01_02_specify_1st_level_2012_07_05_18_10_15_A9993E364706816ABA3E25717850C26C9CD0D89D.m. Then I'll compute a new SHA1 hash of this original function name extended with the SHA1 hash of the analysis parameter sets: SHA1 hash of atf_2012_07_05_18_01_02_specify_1st_level_2012_07_05_18_10_15_A9993E364706816ABA3E25717850C26C9CD0D89D.m is A81F0083 38868103 F1A0DB69 010279D5 5DB3751E. Then I'll create two identical functions, one for MATLAB and one for my debugging purposes, and they will be named atf_A81F008338868103F1A0DB69010279D55DB3751E.m and atf_2012_07_05_18_01_02_specify_1st_level_2012_07_05_18_10_15_A9993E364706816ABA3E25717850C26C9CD0D89D_A81F008338868103F1A0DB69010279D55DB3751E.m. And it's even possible to have several SHA1 hashes of different parameters sets in the same function name this way, eg. one defining the subjects to be included, other defining the data handling parameters etc., then concatenate both or all of them to the filename, and then compute SHA1 hash and write two identical functions as above.

这篇关于扩展MATLAB函数名称的最大长度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆