Archivio

Archivio dell'autore

[Solved] Multiple Matlab instance opening .m files

marzo 14, 2014 Lascia un commento

If you have a new instance of matlab opening each time you open a new file you can check these page for a lot of differente ways of fixing it.
On the official site:

On the forum:

I have an old matlab installation and then I install the new one. After I de-install the old one, the problem arise.
For me worked this suggestion:

“Mohamed Talaat Harb” wrote in message
> The steps you did was right…the only thing missing that before opening Matlab and doing this steps you had to run it as administrator…(Right Click the Matlab shortcut and choose run as administrator)…
> Then in the command line you can write what ever you like without “Matlab can’t…” message
> cwd=pwd; cd([matlabroot ‘\toolbox\matlab\winfun\private’]); fileassoc(‘add’,’.m’) ;cd(cwd); disp(‘Changed Windows file association. M-files are now associated with MATLAB.’);

It worked for me.
You have to manually run Matlab as administrator (also if you already are). Then run the code above, restart matlab and it works !

I also run the same code with .mat and .fig extension.

So my code was:

cwd=pwd; cd([matlabroot ‘\toolbox\matlab\winfun\private’]); fileassoc(‘add’,’.m’) ;cd(cwd); disp(‘Changed Windows file association. M-files are now associated with MATLAB.’);

cwd=pwd; cd([matlabroot ‘\toolbox\matlab\winfun\private’]); fileassoc(‘add’,’.mat’) ;cd(cwd); disp(‘Changed Windows file association. M-files are now associated with MATLAB.’);

cwd=pwd; cd([matlabroot ‘\toolbox\matlab\winfun\private’]); fileassoc(‘add’,’.fig’) ;cd(cwd); disp(‘Changed Windows file association. M-files are now associated with MATLAB.’);

Before find this fix i tried to delete the extension, from explorer, manually from regedit, change the pathdef.m pernissions, but nothing worked utill the above solution. Enjoy.

UPDATE – March 2015

I was trying to do the same with Matlab 2014b 32bit and it failed, since now the “fileassoc” function is considered private. To fix it copy the file “fileassoc.m” from
“MATLAB 2014a\mcr\toolbox\matlab\winfun\private”
in a new folder in
“MATLAB 2014a/toolbox/matlab/winfun public”
and run (sometimes you have to replace the quotes since they could be replaced with non standard ones while publishing in wordpress):

fileassoc(‘add’, {‘.m’,’.mat’,’.mdl’,’.fig’,’.p’,’.mlprj’,’.mexw32′})
fileassoc(‘delete’, {‘.m’,’.mat’,’.mdl’,’.fig’,’.p’,’.mlprj’,’.mexw32′})

cwd=pwd; cd([matlabroot ‘\toolbox\matlab\winfun\private’]); fileassoc(‘add’,’.m’) ;cd(cwd); disp(‘Changed Windows file association. M-files are now associated with MATLAB.’);
cwd=pwd; cd([matlabroot ‘\toolbox\matlab\winfun\private’]); fileassoc(‘add’,’.mat’) ;cd(cwd); disp(‘Changed Windows file association. M-files are now associated with MATLAB.’);
cwd=pwd; cd([matlabroot ‘\toolbox\matlab\winfun\private’]); fileassoc(‘add’,’.fig’) ;cd(cwd); disp(‘Changed Windows file association. M-files are now associated with MATLAB.’);

I’ve also added write permission to the pathdef.m file, but I am not sure it was needed
(http://www.mathworks.com/matlabcentral/answers/93468-why-is-a-new-instance-of-matlab-opened-when-i-double-click-on-a-matlab-file-in-windows-explorer-even)

Enjoy

Categorie:matlab Tag:, , ,

How to add_submenu_page() passing a $variable (parameter=value) with called function

agosto 21, 2013 1 commento

Since in WordPress you cannot pass directly a parameter into the callback function called by the add_submenu_page, I have figured out another simple way to do it.

My problem was to pass a simple parameter into a sub-menu page, something like:
myblog.com/wp-admin/page=my-sub-menu1?parameter=value

You cannot pass value into the callback function, so you CAN’T do this:

add_submenu_page(parent_slug, page_title2, menu_title2, capability, my-sub-menu2, myfunction1(parameter=value )  );

I’ve tried also a secondary function with a wp_redirect, but was not working because headers were alreay set.
Instead I found this solution:

add_submenu_page( parent_slug, page_title, menu_title, capability, my-sub-menu1, myfunction1 );

add_submenu_page(parent_slug, page_title2, menu_title2, capability, my-sub-menu2, myfunction2 );

function myfunction1() {
// Do something
}

function myfunction2() {

     $_REQUEST[‘parameter’] = “value”;

myfunction1(); // Call the original function, but with your parameter set.

}

You just call a secondary function, set the $_REQUEST[‘parameter’] and then call the original function. That’s all !

How to have sticky pages on wordpess

agosto 17, 2013 Lascia un commento

You have to change a single line (#137) in  wp-admin/includes/meta-boxes.php

from:

<?php if ( $post_type == ‘post’ && current_user_can( ‘edit_others_posts’ ) ) : ?>

to:

<?php if ( in_array( $post_type, (array) apply_filters( ‘sticky_post_types’, array( ‘post’, ‘page’  )  ) ) && current_user_can( ‘edit_others_posts’ ) ) : ?>

There is an open thread on the Core Trac WordPress website, with also my contribute:
http://core.trac.wordpress.org/ticket/12702#