Does my for looop make sense?
Afficher commentaires plus anciens

Here is the equation I am using in the code below. I am using a nested for loop. I want to see the value of c(t) when R has two different values, and also when A has 5 differnt values, and then thus plot the data.
for t, I am using linespace.
Can anyone confirm please if my code make sense? I think I have coded the for loop correctly, but i am not entiry sure.
clc, clear all, close all
% two values for R
R = [10 30];
% 5 vaules for a
a = [0.1 0.2 0.5 0.75 1];
% t for time
t = linspace(0,10,100);
hold on
for i = 1:2
for j = 1:length(a)
ct = R(i)-R(i)*(exp(-a(j)*t));
plot(t,ct)
text(max(t)/2,max(ct),num2str(a(i)))
end
end
Réponse acceptée
Plus de réponses (1)
for i = 1:numel(R)
for j = 1:numel(a)
ct(i,j,:) = R(i)*(1-exp(-a(j)*t));
end
end
plot(t,ct(1,1,:)) % plot curve for R = 10 and a = 0.1
Catégories
En savoir plus sur Get Started with Signal Processing Toolbox dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
