Is there any way to set which browser will open a link within the Matlab program?

Is there any way to set which browser will open a link within the Matlab program?
When I do
link1 = 'https://earth.google.com/web/@';
web(link1, '-browser')
it always opens the default browser, which is not the one I want to use for the particular program. I don't want to have to keep resetting the default browser to my preferred default after each time I run the program.

 Accepted Answer

mark - could you use system to launch a browser for the given URL? For example, on my Mac I can do either
system('open -a Safari https://www.mathworks.com/matlabcentral/answers/index')
or
system('open -a "Google Chrome" https://www.mathworks.com/matlabcentral/answers/index')
to open this link in Safari or Chrome respectively.

5 Comments

Please share the line of code that you have written. The above examples are for a Mac OS and so the commands may be different for the OS and browser that you are trying to use.
Also, please clarify what you mean by it doesn't work. Do you observe an error, and if so, what is it? Perhaps if you consider the output parameters for this function, then you might get an idea of what is going wrong.
command = 'open -a "Google Chrome" https://www.mathworks.com/matlabcentral/answers/index';
[status,cmdout] = system(command)
Ok, here's simplified code. (I'm on Mac.) My default browser is Safari, and I need to make Chrome the default for this to work, since Safari can't run Google Earth. I'd prefer the code to make Chrome the default and back instead of having to do it manually.
clear all
brow1 = 'open -a "Google Chrome" ';
link1 = 'https://earth.google.com/web/@';
hrz = '35y,0h,0t,0r';
for ii = 1:1
c1 = 0;
c2 = 0;
az = 0;
dz = 100000;
sc1 = num2str(c1); % LATITUDE
sc2 = num2str(c2); % LONGITUDE
saz = num2str(az); % AZIMUTH - HAS ANY EFFECT???
sdz = num2str(dz); % ELEVATION
GELonLat1 = [brow1, link1, sc1,',',sc2,',',saz,'a,',sdz,'d,', hrz];
web(brow1, GELonLat1, '-browser');
end
So the idea is to use system instead of web. Your code would then become (and I just tested this on my Mac)
brow1 = 'open -a "Google Chrome" ';
link1 = 'https://earth.google.com/web/@';
hrz = '35y,0h,0t,0r';
for ii = 1:1
c1 = 0;
c2 = 0;
az = 0;
dz = 100000;
sc1 = num2str(c1); % LATITUDE
sc2 = num2str(c2); % LONGITUDE
saz = num2str(az); % AZIMUTH - HAS ANY EFFECT???
sdz = num2str(dz); % ELEVATION
GELonLat1 = [brow1, link1, sc1,',',sc2,',',saz,'a,',sdz,'d,', hrz];
system(GELonLat1); % <---- use system NOT web
end

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!