Coder deleting variable definitions

Why oh why does coder feel the need to delete my variable definitions from time to time? It is unbelievably frustrating having to redefine 200+ variables.

댓글 수: 13

Walter Roberson
Walter Roberson 2012년 6월 13일
Adam, as a work-around, could you perhaps put the variable definitions into a different file and #include that file ?
Adam Kaas
Adam Kaas 2012년 6월 13일
So create a file that is full of stuff like:
double Var1;
int Var2;
And select that as a test file to have all of the variables autodefined?
Walter Roberson
Walter Roberson 2012년 6월 13일
Write the definitions into YourFileName.h. Then at the point in the C code that you need the variables defined, you would put the line
#include "YourFileName.h"
This has the effect of inserting everything from YourFileName.h as-if it had all been typed in at that point in the source.
Walter Roberson
Walter Roberson 2012년 6월 13일
Note: the double-quote marks are important for the syntax.
Adam Kaas
Adam Kaas 2012년 6월 13일
I see what you are saying. I understand how to do that in the C language. I was more referring to the Overview tab in MATLAB Coder where it asks for all of my entry-point files.
Kaustubha Govind
Kaustubha Govind 2012년 6월 13일
Adam: Are these variables not being used in the rest of your code? I would expect the variable definitions to be removed only as an optimization.
Adam Kaas
Adam Kaas 2012년 6월 13일
Maybe I'm not understanding how to use coder properly. If I want a file to be converted to C, I'd put it in my entry-point files section. Let's say the file is called S1.m. In S1.m I have two variables, zeta and w, that need to be defined before the function will compile. One is a double(1 x 1) and the other is a double(1 x 200). Once I do that, assuming I don't have any other errors within my code, it will compile. But from time to time, those definitions I have in place for zeta and w will disappear.
Walter Roberson
Walter Roberson 2012년 6월 13일
This would not be an entry-point file.
Kaustubha Govind
Kaustubha Govind 2012년 6월 14일
Are the variable zeta and w being used in some part of S1.m?
Adam Kaas
Adam Kaas 2012년 6월 14일
Yes they are. If I don't put them as a field in the entry-point file, the code will not be generated
Adam Kaas
Adam Kaas 2012년 6월 14일
I also believe I figured out how the definitions are getting deleted. When I highlight more than one entry-point file (primarily on accident), that's when it occurs. I don't know how to make it happen but I know every time it happens, I have at least 2 files highlighted.
Kaustubha Govind
Kaustubha Govind 2012년 6월 14일
Adam: I think I'm a little confused about your workflow. Perhaps you should consider sending your files and reproduction steps to MathWorks Tech Support and verify if this is expected behavior or a bug?
Adam Kaas
Adam Kaas 2012년 6월 14일
I will send this to them. I think it is a bug. I figured out how to recreate the problem 100% of the time though. You can test this yourself and let me know if your results vary. Create a coder project, and on the overview tab, when you add an entry-point file, make sure you define at least one field. Then left click on the entry-point files name and hold it just longer than a click. If you drag that file even the slightest, your field definitions will be erased.

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

 채택된 답변

Fred Smith
Fred Smith 2012년 6월 26일

1 개 추천

Hi Adam,
Sorry to hear about your frustration. If you have 200 variables you might want to consider a different approach.
Have you looked at using codegen from the command-line instead of the UI? You can use "pre-conditioning" to incorporate your type definitions directly into your MATLAB code. This mechanism is verbose but solid. In many cases you can auto-generate the pre-conditions using some helper scripts. This feature is also available through the UI as of R2012a although it is somewhat hidden in the Settings dialog.
Another possibility in the UI, is to define your inputs by example. If you have appropriates variables in the base workspace, MATLAB coder can automatically figure out the types from those.
Hope this helps,
Fred

댓글 수: 1

Adam Kaas
Adam Kaas 2012년 6월 26일
Thanks Fred. I never ended up getting it reported (ironically the bug report page bugged out...) but thankfully I got everything I needed from Coder and no longer need to use it. I will look at using codegen in the future as it sounds to be a much more painless process. Thanks again!

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

추가 답변 (1개)

Rich McKeever
Rich McKeever 2012년 6월 26일

1 개 추천

Adam,
We saw your post about the issue here and fixed the bug yesterday. A patch is available here, but I also second Fred's suggestion of using other methods for defining large numbers of inputs.
Thanks,
Rich

카테고리

도움말 센터File Exchange에서 DSP Algorithm Acceleration에 대해 자세히 알아보기

제품

태그

질문:

2012년 6월 13일

Community Treasure Hunt

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

Start Hunting!

Translated by