call a input variable in a function

I have created a model using pdetool command and kept the model under a function with name 'heat.m' as follows:
function A = heat (B,~)
Model = createpde('thermal','transient');
............
C = B/3.2;
E = C/5.;
..........
end
Calling the above function within a for loop in separate script file. The for loop are as follows:
t1=0:0.1:1;
for j=1:length(t1)
D(j) =.....;
A = heat (D(j));
end
I am not getting any results. I understand that I am doing wrong while calling input variable B. At each iteation, the variable B will be replaced by D(j). How can I replace the input variable correctly?

댓글 수: 4

KSSV
KSSV 2021년 4월 5일
Check the dimensions of B and D(j) are they equal? You need to see how the input B is.
mathru
mathru 2021년 4월 5일
편집: mathru 2021년 4월 5일
The dimensions of B and D are different but the dimensions of B and D(j) are same. Actually, when the function is calling within the for loop, B is replacing by D(j) and then the function is solving.
Stephen23
Stephen23 2021년 4월 5일
"I am not getting any results."
Please explain exactly what you expect, and what you observe (and how you are checking it).
"I understand that I am doing wrong while calling input variable B."
Why do you understand that? The most obvious bug I can see is the lack indexing into the output array, which means that your code will overwrite all A data except for the data from the last iteration.
mathru
mathru 2021년 4월 6일
편집: mathru 2021년 4월 6일
Code is showing that it is running but not giving any output.
You are right. Output array is the problem. Trying to solve the problem.

댓글을 달려면 로그인하십시오.

답변 (1개)

DGM
DGM 2021년 4월 6일

0 개 추천

The function definition indicates that A is the output array.
function A = heat (B,~)
But at least from what's shown here, A is never defined within the function scope, so nothing will be returned.

질문:

2021년 4월 5일

편집:

2021년 4월 6일

Community Treasure Hunt

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

Start Hunting!

Translated by