Effacer les filtres
Effacer les filtres

How to make a loop to add 3 elemts in matrix of zeros(n,n)?

1 vue (au cours des 30 derniers jours)
Avtar Singh
Avtar Singh le 22 Août 2014
Commenté : Avtar Singh le 23 Août 2014
n= input('enter the value of n:-->');
A= zeroes(n,n); %n must be greater than 3
i want to add [1 4 1] in second row after skipping first 0 if n=4
and if n=5 add [1 4 1] in second row after skipping first 0 and add [ 1 4 1] to third row after skip two 0`s.
for example:
A = [0 0 0;
0 0 0;
0 0 0]
if n=3
add [ 1 4 1] to 2nd row
then
A = [ 0 0 0;
1 4 1;
0 0 0]
if n=4
A = [0 0 0 0;
0 1 4 1;
0 0 0 0]
if n=5
A = [ 0 0 0 0 0;
1 4 1 0 0;
0 1 4 1 0;
0 0 1 4 1;
0 0 0 0 0];
similarly ahead
help me

Réponse acceptée

Mikhail
Mikhail le 22 Août 2014
Modifié(e) : Mikhail le 22 Août 2014
As i understand, u need this:
n= input('enter the value of n:-->');
A= zeroes(n,n); %n must be greater than 3
for i=2:n-1 % loop from 2nd to (n-1) row
A(i,:)=[zeros(1,i-2),[1 4 1],zeros(1,n-i-1)] %explicit structure of row i
end
  10 commentaires
Avtar Singh
Avtar Singh le 23 Août 2014
thanks bro
Avtar Singh
Avtar Singh le 23 Août 2014
clear all
a=[1,1,0;4,4,1;7,5,1;15,2,1;6,4,3]
n = input('enter the number of passing points of curve:--->>')
A= zeros(n,n); %n must be greater than 3
for i=2:n-1 % loop from 2nd to (n-1) row
A(i,:) = [zeros(1,i-2),[1 4 1],zeros(1,n-i-1)]; %explicit structure of
row i
end
A(1,1)=1;
A(n,n)=1;
R=[0 0 0; 3*(a(3,:)-a(1,:)); 3*(a(4,:)-a(2,:));3*(a(5,:)-a(3,:));0 0 0];
X=inv(A)
T=X*R;
u=[0:0.01:1]'
U=[u.^3 u.^u u u.^0];
M=[2 -2 1 1;-3 3 -2 -1 ;0 0 1 0;1 0 0 0];
B=[0 0 0;a(1,:);0 0 0;T(2,:)];
P=U*M*B;
plot3(P(:,1),P(:,2),P(:,3));
hold on
B1=[a(1,:);a(2,:);T(2,:);T(3,:)];
P1=U*M*B1;
plot3(P1(:,1),P1(:,2),P1(:,3));
I want to join these curves by smooth one but i cant help me

Connectez-vous pour commenter.

Plus de réponses (0)

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!

Translated by