Borrar filtros
Borrar filtros

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

1 visualización (últimos 30 días)
Avtar Singh
Avtar Singh el 22 de Ag. de 2014
Comentada: Avtar Singh el 23 de Ag. de 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

Respuesta aceptada

Mikhail
Mikhail el 22 de Ag. de 2014
Editada: Mikhail el 22 de Ag. de 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 comentarios
Avtar Singh
Avtar Singh el 23 de Ag. de 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

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Loops and Conditional Statements en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by