How to pass if statement string from excel to Matlab and construct a function
2 次查看(过去 30 天)
显示 更早的评论
Hey everyone,
So I need users to be able to input different possible conditional statements in excel, where then matlab reads in the conditional statement and converts it to a function that can be executed on Matlab data. I believe using a char array input from Excel would be the best way to approach this but am unsure. I could also probably build a custom parser for this but I'm hoping there is a better and/or faster approach. I was expecting to use str2func() or feval() to execute these inputs.
Here is an example of what I was thinking in terms of input in Excel:
Here each event would represent a row and there is always an initial statement to execute. However, there may or may not be conditional statements to execute. In addition it is possible for a user to want to enter more than one if statement clause as shown above. Lastly, the _n is to represent which index to reference, so DRstart_n+1 in Excel is equivalent to DRstart(n+1) in Matlab. The way I've written the conditions and outcomes can be changed and aren't set in place.
This question is most likely too specific, but any advice or insight would be greatly appreciated before tackling this.
If you have any questions please ask!
Thanks!
0 个评论
采纳的回答
Walter Roberson
2022-8-12
You are designing your own language representation in Excel. Unless you deliberately make it mechanically translatable to MATLAB by having all of the user input be matlab code, then you are going to need to build a parser. That can get moderately complex. See for example https://www.mathworks.com/matlabcentral/fileexchange/32769-mparser (there are other similar projects around.)
0 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Data Import from MATLAB 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!