How to pass if statement string from excel to Matlab and construct a function

2 ビュー (過去 30 日間)
Ryan
Ryan 2022 年 8 月 12 日
回答済み: Walter Roberson 2022 年 8 月 12 日
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!

採用された回答

Walter Roberson
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 件)

カテゴリ

Help Center および File ExchangeSpreadsheets についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by