필터 지우기
필터 지우기

Using loop instead of hardcoding

조회 수: 2 (최근 30일)
Khang Nguyen
Khang Nguyen 2019년 5월 20일
편집: Rik 2019년 5월 26일
s
Hi everyone,
I want to use for loop instead of just typing particular h values how can I do that ?.
Furthermore, my ta and tb got 3 elements whereas my tc got 11 elements and td got 21 elements, same as va vb vc vd respectively.
Thanks in advance

답변 (1개)

Rik
Rik 2019년 5월 20일
Please post your code as code instead of a picture. What exact function are you using? The only midpoint function I can find in the documentation is the Deep Learning Toolbox midpoint function, which has a different syntax.
Anyway, the stated problem itself is easily solved like this (I used cell due to the differently sized variables):
h=[0.7 0.5 0.1 0.05];
t=cell(1,numel(h));
v=cell(1,numel(h));
for k=1:numel(h);
[t{k},v{k}]=midpoint(dvdt,tspan,v0,h(k));
end
  댓글 수: 2
Khang Nguyen
Khang Nguyen 2019년 5월 20일
Firstly, thanks for helping.
I used your code, and it states that "Conversion to cell from double is not possible"
Rik
Rik 2019년 5월 20일
편집: Rik 2019년 5월 26일
Then you will have to describe better what your function is doing. What is the input and output? I don't see how you could get that error with my code. Please attach your entire code as an m-file, or try to reduce it to a MWE so we can run your code without any other dependencies and can reproduce your issue.

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

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by