Looping between two functions

3 Ansichten (letzte 30 Tage)
DARLINGTON ETAJE
DARLINGTON ETAJE am 30 Jun. 2021
Kommentiert: DARLINGTON ETAJE am 30 Jun. 2021
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.

Antworten (1)

Jan
Jan am 30 Jun. 2021
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 Kommentar
DARLINGTON ETAJE
DARLINGTON ETAJE am 30 Jun. 2021
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];

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by