Hello everyone, In the following code, I am trying to record V values in the matrix V_mat not just the last value. Please help me how can I do it.
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Mohammad Dawoodzada
le 13 Oct 2021
Commenté : Mohammad Dawoodzada
le 13 Oct 2021
Code
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/766576/image.png)
0 commentaires
Réponse acceptée
Geoff Hayes
le 13 Oct 2021
@Mohammad Dawoodzada - initialize the matrix outside of your loops (rather than on each iteration of the inner loop) and keep track of which index to insert the new V into. For example,
V_mat = zeros(10, 4); % initialize here
index = 1; % current index variable
for r = Ri:1:Ro
for Theta = 3:1:6
Z1 = r*cos(Theta)*cos(Beta)-((P*Theta)/(2*pi))*sin(Beta);
Z2 = r*cos(Theta)*cos(Beta)-(((P*Theta)/(2*pi))-(P/N))*sin(Beta);
if Z2>Zwl && Z1>Zwl
dT = 0;
elseif Z2>=Zwl && Z1<= Zwl
dT = ((Zwl-Z1)/(Z2-Z1))*(P/N)*r;
elseif Z2<Zwl && Z1<Zwl
dT = (P/N)*r;
else
fprintf('No result was found')
end
fun = @(x,y) dT+0*x+0*y;
V = integral2(fun , Ri, Ro, 0, 2*pi);
V_mat(index) = V; % update V_mat
index = index + 1; % increment index
end
end
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Loops and Conditional Statements dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!