Looping between two functions
10 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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.
0 comentarios
Respuestas (1)
Jan
el 30 de Jun. de 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 comentario
Ver también
Categorías
Más información sobre Loops and Conditional Statements en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!