MATLAB Answers


"Improper index matrix reference" error

Asked by Jess
on 15 Feb 2013

Hi all,

I've been trying to rewrite a line of Matlab code so that I can convert the code into C using Matlab Coder. The original line was this:

my_index = cellfun(@(x)~isempty(x),regexp({},'my_string'));

At the moment the code I've got to do the same as the line above is:

n = numel(my_results);
my_results = false(n,1);
for ii = 1:n
  my_results(ii) = coder.ceval(strstr(my_results(ii).name,'my_string'));
len_new_my_results = length(new_my_results);
for ii = len_new_my_results:-1:1
   my_index(ii) = ~isempty(new_my_results{ii});

This however is giving me an error saying "Improper index matrix referencing" at the line my_results(ii) = coder.ceval(strstr(my_results(ii).name,'my_string'));

I have tried reading up about what it means and I think it has something to do with a variable being an input to a function (this is true in my case, my_results is an input to the function where this piece of code is)? Is there a way to get around it?

Any pointers in the right direction will be greatly appreciated. Thank you.

  1 Comment

I have restored the original text of this question.

Evelina, this question has a clear subject and answer, so it may be valuable to someone else in the future. If you have a good reason why it should be removed from MATLAB Answers, please flag the question, explain why it should be deleted, and an administrator or high-reputation contributor will consider deleting the question. Please do not simply edit your question away.


No products are associated with this question.

1 Answer

Answer by Sean de Wolski
on 15 Feb 2013

Looking at:

doc coder.ceval

coder.ceval('cfun_name', cfun_arguments)

So above the correct syntax looks like it would be:


I.e. first the name of the C function, then the two inputs to it.

  1 Comment

Are you trying to run it in matlab or is that in the generated code/mex file etc?

Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

MATLAB Academy

New to MATLAB?

Learn MATLAB today!