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 CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

제품


릴리스

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by