Effacer les filtres
Effacer les filtres

Why should we write x(i,1)=cos(theta(1,i) in this format while using the for loop?

1 vue (au cours des 30 derniers jours)
S Priya
S Priya le 17 Août 2021
Commenté : S Priya le 17 Août 2021
I have a doubt regarding this way of represention.
for i=1:n+1
x(i,1)=R*cos(Theta_n(1,i)
Why cant we represent it as-
x(i)=R*cos(Theta_n(i))

Réponse acceptée

KSSV
KSSV le 17 Août 2021
Modifié(e) : KSSV le 17 Août 2021
x = zeros(n+1,1) ;
for i=1:n+1
x(i)=R*cos(Theta_n(i)
You can very much write like you shown. But keep in mind that the variables should be vectors.
  4 commentaires
KSSV
KSSV le 17 Août 2021
You can simply try and check the output your self.
When you try:
n = 3 ;
zeros(n+1)
ans = 4×4
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
You will get a matrix.
If you want to get a vector, you should specify:
n = 3 ;
zeros(n+1,1)
ans = 4×1
0 0 0 0
zeros(1,n+1)
ans = 1×4
0 0 0 0

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Logical 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!

Translated by