Passing the output of SWITCH statement through a function

15 ビュー (過去 30 日間)
Andy
Andy 2024 年 2 月 18 日
編集済み: Andy 2024 年 2 月 19 日
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 Bblanc
Nathan Bblanc 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 Center および File ExchangeMatrix Indexing についてさらに検索

製品


リリース

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by