Looping between two functions

조회 수: 3 (최근 30일)
DARLINGTON ETAJE
DARLINGTON ETAJE 2021년 6월 30일
댓글: DARLINGTON ETAJE 2021년 6월 30일
Hi. Please kindly help me solve this problem. the problem really lies from when ghs is mentioned.
function [bhs,ahs,cbs]=btime(t1,t2,t3)
bhs=(t1*t2)+t3;
ahs=t1+t3;
cbs=t2./3;
end
function [abk,kba,t3]=ctime(bhs,cbs)
abk=27.3.*bhs;
kba=bhs+cbs;
t3=35*(abk+kba);
end
wqe=[1;2;3;4;5;6;7;8;9;10;11;12;13;14;15];
kli=[51;52;53;54;55;56;57;58;59;60;61;62;63;64;65];
bbc=(21:1:35)';
hsd=size(kli,1);
kas=zeros(hsd,1);
sak=zeros(hsd,1);
cbb=zeros(hsd,1);
abc=zeros(hsd,3);
for i=1:hsd
kas(i)=wqe(i);
sak(i)=kli(i);
cbb(i)=bbc(i);
end
abc(1,:) = [kas(1) sak(1) cbb(1)];
for h=2:1:hsd
abc(h,:)=[kas(h) sak(h) cbb(h)];
end
matrix{1}=abc(1,:);
for i = 2:hsd
matrix{i}=abc(1:i,:);
end
ghs=([]);
for iiv=1:1:hsd
ghs(iiv)=(matrix{1,iiv}(:,:));
t1=ghs(:,1);
t2=ghs(:,2);
t3=ghs(:,3);
[bhs(iiv),ahs(iiv),cbs(iiv)]=btime(t1(iiv),t2(iiv),t3(iiv))
[abk(iiv),kba(iiv)]=ctime(bhs(iiv),cbs(iiv))
end
Final_Answer=[bhs kba]; % The goal is to put each new bhs and cbs under the previous one.

답변 (1개)

Jan
Jan 2021년 6월 30일
Simplify your code:
for i=1:hsd
kas(i)=wqe(i);
sak(i)=kli(i);
cbb(i)=bbc(i);
end
does the same as:
kas = wqe;
sak = kli;
cbb = bbc;
The code:
abc(1,:) = [kas(1) sak(1) cbb(1)];
for h=2:1:hsd
abc(h,:)=[kas(h) sak(h) cbb(h)];
end
does the same as:
abc = [kas, sak, cbb];
The line:
ghs(iiv)=(matrix{1,iiv}(:,:));
is equivalent to:
ghs(iiv) = matrix{1,iiv};
But I do not see, why you create ghs as array at all.
It is not clear, what you want to achieve. With a simplified code this gets clearer, I hope, or if you explain this in detail.
  댓글 수: 1
DARLINGTON ETAJE
DARLINGTON ETAJE 2021년 6월 30일
Thanks for your comments Jan. and you are right, some of those codes could be easier...take note that the size of ghs increases on every loop. The goal is to feed the new sets of t1, t2, and t3 to the two fucntions and finally produce Final_Answer. The newer bhs and kba are concatenated underneat. I know the process seems hard but I really need it. Thanks
Final_Answer=[bhs kba];

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

카테고리

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