How to take x as a vector in for loop?
Afficher commentaires plus anciens
NN=zeros(nx+1,nx+1);
xx=0.998;
for i=1:nx+1
count=1;
for x=dx:length: nx+1
if(i-1)*xx<=x<=i*xx
i;
NN(i,count)=(x-(i-1)*dx)/dx;
elseif i*xx<=x<=(i+1)*xx
i;
NN(i,count)=((i+1)*dx-x)/dx;
end
NN(NN<0)=0;
count=count+1;
end
end
This code shows dimension error in
T_check = interp1(xts,pts,x,'linear');
because x is showing only one value here. Anyone please guide me how to correct x?
1 commentaire
Stephen23
le 7 Sep 2017
@Qudsiya Irum: your code is very badly indented. Bad code alignment is a common way that beginners hide errors in their code. Fixing code indentation is easy: click ctrl+i in the MATLAB editor.
Réponse acceptée
Plus de réponses (1)
Qudsiya Irum
le 8 Sep 2017
Modifié(e) : Stephen23
le 8 Sep 2017
2 commentaires
Stephen23
le 8 Sep 2017
"Please see the code, is this correct in indent??"
No, that is still a mess. You should use the default MATLAB indentation, which occurs automatically when you use the MATLAB editor.
Eric
le 8 Sep 2017
"If you want x to be the entire vector, set x=dx:length:nx+1 again on its own after the for loop."
As I mentioned previously, the way to get x as a vector with minimal changes to your code is to add the line
x =dx:xlength:nx+1
to the end of your code.
Catégories
En savoir plus sur Loops and Conditional Statements 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!