# How to vary the interval of this matrix?

7 ビュー (過去 30 日間)
Pedro Guevara 2018 年 7 月 26 日
Edited: per isakson 2018 年 7 月 28 日
Thank you all for the reply. I already solved, in part, the problem I had, but now I have another. I have this line of code:
prueba=['MK_G', num2str(px(j,1)),'(4:6,4:6)'];
where 'MK_G', num2str (px (j, 1)) are N number of matrices that are already created. but I require, in some way, that the intervals of the matrix that I am evaluating (in this case 4: 6,4: 6) are in some way variable. I thank you for your collaboration with this new problem.

#### 6 件のコメント

Pedro Guevara 2018 年 7 月 26 日
while i>=1 && i<=VarElem_F %while 2 start
[px, py]=find(Nodos==datos(i,col)) %Busca posicion de nodos iguales
if length(py)==1
jj=1;
j=0;
else
jj=1;
j=1;
end
if (py(jj,1)==1 && py(j+1,1)==1) % If start 1
for j = 1: length(px)
prueba=['MK_G', num2str(px(j,1)),'(1:3,1:3)'];
prueba=eval(prueba);
aux=aux+prueba;
M_cons=aux;
end
prueba=0;
aux=0;
j=1;
px=0;
py=0
elseif py(j,1)==2 && py(j+1,1)==2
for j = 1: length(px)
prueba=['MK_G', num2str(px(j,1)),'(4:6,4:6)'];
prueba=eval(prueba);
aux=aux+prueba;
M_cons=aux;
end
prueba=0;
aux=0;
j=1;
elseif py(jj,1)~=py(j+1,1)
for j = 1: length(px)
prueba=['MK_G', num2str(px(j,1)),num2str(j+1:j+2,j+1:j+2)];
prueba=eval(prueba);
aux=aux+prueba;
M_cons=aux;
end
prueba=0;
aux=0;
j=1;
elseif py(jj,1)~=py(j+1,1)
end % If end 1
if i == VarElem_F && col==6 %If start 2
col=7;
f = 1;
i=1;
else
i=1+i;
end %If end 2
end %while 2 end
Steven Lord 2018 年 7 月 26 日
Looks like a continuation of this Answer.
jonas 2018 年 7 月 26 日
Ugh.. Looks like he didn't pick up on the advice regarding dynamic variables.

サインイン to comment.

### 件の回答 (1)

jonas 2018 年 7 月 26 日

formatSpec = '(%d:%d,%d:%d)';
str = sprintf(formatSpec,i,i+2,i,i+2)
prueba=['MK_G', num2str(px(j,1)),str];
You want the length of the interval to be variable as well? Just change the 2 to a variable.

#### 2 件のコメント

Pedro Guevara 2018 年 7 月 26 日
I will try this code. thank you very much.
jonas 2018 年 7 月 26 日
No problem! I changed to sprintf for building the string instead, a bit more elegant.
EDIT: Ugh... Don't name variables dynamically. It's not good practice. Better use cell arrays or dynamic field variables.

サインイン to comment.

サインイン してこの質問に回答します。

R2017b

Translated by