필터 지우기
필터 지우기

How to vary the interval of this matrix?

조회 수: 1 (최근 30일)
Pedro Guevara
Pedro Guevara 2018년 7월 26일
편집: 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
Steven Lord
Steven Lord 2018년 7월 26일
Looks like a continuation of this Answer.
jonas
jonas 2018년 7월 26일
Ugh.. Looks like he didn't pick up on the advice regarding dynamic variables.

댓글을 달려면 로그인하십시오.

답변 (1개)

jonas
jonas 2018년 7월 26일
편집: jonas 2018년 7월 26일
i is your variable, then
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
Pedro Guevara 2018년 7월 26일
I will try this code. thank you very much.
jonas
jonas 2018년 7월 26일
편집: 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.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 MATLAB에 대해 자세히 알아보기

제품


릴리스

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by