How to add for loop in my code to get a table of result and plot it?
Afficher commentaires plus anciens
Hi;
My problem is that I want to have a table of result including the first coloumn is "R" (from 2 to 7) and the second one is "N_states" (for each "R" I should have a spesefic "N_states") and then plot the table. (Hint: the code (from line 3 to 11) generets just one "N_states" for one "R = 7" corectly but I want to have different "N_states" for different "R" and then plot "N_states" vers. "R")
This is my code:
for R = 2:7
%
%R = 7;
N_states = 0;
for nx = 1:R
for ny = 1:R
if ((nx.*nx + ny.*ny) <= R.*R)
N_states= N_states + 1;
end
end
end
%
R = R + 1;
end
T = table(R(:),N_states(:));
plot (T)
2 commentaires
Sindar
le 9 Mar 2020
You need to store the values of N_states separately for each R. My advice would be to define R_vec outside the loop, loop over ind=1:length(R_vec), and index into R_vec and N_states with ind.
Since this is clearly a HW problem and essentially the same question has been asked many times before, I'll leave the specific coding to you
Alireza Alipour
le 12 Mar 2020
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Matrices and Arrays 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!