Passing the output of SWITCH statement through a function

6 次查看(过去 30 天)
Hi,
I was wondering if anyone may be able to assist with a problem that seems to be driving me mad. I am designing an app with App Designer and through the help of the good people on here, I nearly have it working, just one problem remains.
In my code for the App I have a switch statement dependant on which media my electromagnetic wave is travelling through called "er". What I wish to do is pass the value calculated for er through to a function where a numerical solution may be approximated.
Initially, I wrote the code as executable function and it worked for the different media from the SWITCH statement, however I have 'bolted' the App onto this code so it has a easy access interface.
Can you pass a value from a SWITCH statement through to a function? I have included the code for my app and also the function below and have shown where the problem lies - "Error using fdtd_time_reversal (line 187) Arrays have incompatible sizes for this operation".
Hoping someone may be able to shed some light on this.
Many thanks,
Andy

采纳的回答

nathan blanc
nathan blanc 2024-2-18
As you can see from the error message, the function "fdtd_time_reversal" is run, and encounters an error on line 187:
loss = 1 - ((sig*dt)./(er*e0));
The error message indidicates that the array sizes are not what you expected them to be. maybe er is a vector and supposed to be a scalar? try placing a debugger on this line and running the app, and then investigate each variable (sig,dt,er,e0) to see if they are the size you expected. It is also possible that one of the multiplications should be with .* (mutiplying all terms) instead of * (matrix multiplication).
  1 个评论
Andy
Andy 2024-2-19
Problem solved! nargin was set at 13 instead of 14 so it would not allow the function tto run that code.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Develop Apps Using App Designer 的更多信息

产品


版本

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by