Note: This discussion is about an older version of the COMSOL Multiphysics® software. The information provided may be out of date.

Discussion Closed This discussion was created more than 6 months ago and has been closed. To start a new discussion with a link back to this one, click here.

COMSOL external MATLAB function

Please login with a confirmed email address before reporting spam

Hello forum.

I want to use an external matlab function to define a local heat transfer coefficient distribution.

If I use a very simple external function, everything works fine:

for example:

function value=alpha(z)
value = ones(size(z))*65000;
end

My function will load an object with the current data from a *mat - file and will read the data and give it back to COMSOL
something like that:

function out=AlphaZ1(z)

global pipe1;
path('V:\30_Numerik\COMSOL\Thermosyphon_2.0alpha\20130218001\classes',path)
strStoredVariableDataFileName = 'V:\30_Numerik\COMSOL\Thermosyphon_2.0alpha\20130218001\pipe1.mat';
load(strStoredVariableDataFileName)
value=pipe1.CondenserSection.GetAlphaZ(z');
out=round(value');

end

Unfortunately I always get an error message:

Attempted to access value(:,1); index out of bounds because size(value)=[0,0].
with no further details

If I save the z - vector to an mat-file and later try to call the function with this z-vector, it works properly and I get the correct heat transfer distribution.

Is there a way to analyse the error message and to find where it occurs? I already tried to catch all errors with a try-catch statement in MATLAB, but that does not help

Matthias

1 Reply Last Post Feb 18, 2013, 12:57 p.m. EST

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago Feb 18, 2013, 12:57 p.m. EST
I may could specifiy the reason, but don't know any solution.

I think MATLAB has a problem during loading of object from mat-file:

(in the current folder, there is a file with the name pipe1.mat, that contains an object instance pipe1)

load pipe1;

the error message in COMSOL is (as I already have written above):
Attempted to access value(:,1); index out of bounds because size(value)=[0,0].

If I try to load the object from the MATLAB command window, everything works fine. It is possible to make it global and use it in the MATLAB external function. But the content of the object changes after each calculation step and therefore I have to load it directly within the MATLAB external function.
I may could specifiy the reason, but don't know any solution. I think MATLAB has a problem during loading of object from mat-file: (in the current folder, there is a file with the name pipe1.mat, that contains an object instance pipe1) load pipe1; the error message in COMSOL is (as I already have written above): Attempted to access value(:,1); index out of bounds because size(value)=[0,0]. If I try to load the object from the MATLAB command window, everything works fine. It is possible to make it global and use it in the MATLAB external function. But the content of the object changes after each calculation step and therefore I have to load it directly within the MATLAB external function.

Note that while COMSOL employees may participate in the discussion forum, COMSOL® software users who are on-subscription should submit their questions via the Support Center for a more comprehensive response from the Technical Support team.