Passing the output of SWITCH statement through a function

15 views (last 30 days)
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

Accepted Answer

Nathan Bblanc
Nathan Bblanc on 18 Feb 2024
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 Comment
Andy
Andy on 19 Feb 2024
Problem solved! nargin was set at 13 instead of 14 so it would not allow the function tto run that code.

Sign in to comment.

More Answers (0)

Products


Release

R2023b

Community Treasure Hunt

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

Start Hunting!