필터 지우기
필터 지우기

Removing cellfun, regexp and function handles

조회 수: 1 (최근 30일)
Jess
Jess 2013년 2월 13일
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_results.name},'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'));
end
len_new_my_results = length(new_my_results);
for ii = len_new_my_results:-1:1
my_index(ii) = ~isempty(new_my_results{ii});
end
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
Randy Souza
Randy Souza 2013년 2월 19일
I have restored the original text of this question.
Evelina, this question has a clear subject and an accepted 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.

댓글을 달려면 로그인하십시오.

채택된 답변

Sean de Wolski
Sean de Wolski 2013년 2월 13일
Don't convert to cell:
new_my_results = regexp({my_results.name},'my_string');
Instead use (I assume this is a struct array):
n = numel(my_results);
my_results = false(n,1);
for ii = 1:n
my_results(ii) = mystrfind(my_results(ii).name,'my_string');
end
You'll have to write your own mystrfind since none of the string finding things appear to be supported for codegen. This could be doen real easily with a for-loop over the values. You could also consider using coder.ceval to just use the C string finding function.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 MATLAB Coder에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by